﻿using System;
using Microsoft.Win32;
using System.Data;
using System.Collections;
using System.Xml;
using System.Data.OracleClient;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace LibKetoan
{
	public class AccessData
	{	
		public string Msg="Quản lý kế toán";
		public const string links_userid="links",links_pass="link7155019s20",uxxx="tuneig@mp",pxxx="tuneig@mp";
		public string insert = "ins", delete = "del";
		public const int chucnang_k = 6, lctug_k = 9;
		string sConn="Data Source=MEDISOFT;user id=medibv;password=medibv";
		private int iRownum=1;
		OracleDataAdapter dest;
		OracleConnection con;
		string sComputer=null;
		string sql="",userid="medibv",service_name="medisoft";
		OracleCommand cmd;
		DataSet ds=null;

		public AccessData()
		{
			if (Maincode("Con")!="") sConn=Maincode("Con");			
			sComputer=System.Environment.MachineName.Trim().ToUpper();
			userid=sConn.Substring(sConn.LastIndexOf("=")+1).Trim();
			service_name=sConn.Substring(sConn.IndexOf("=")+1,sConn.IndexOf(";")-1-sConn.IndexOf("=")).Trim();
			upd_dmcomputer(sComputer);
			ds=get_data("select rownum,computer from dmcomputer");
			DataRow r=getrowbyid(ds.Tables[0],"computer='"+sComputer+"'");
			if (r!=null) iRownum=int.Parse(r["rownum"].ToString());
		}

		public string user{get {return userid;}}
		public string service{get {return service_name;}}
		private string get_conn_d(string mmyy)
		{
			return "Data Source="+service_name+";user id="+userid+"d"+mmyy+";password="+userid+"d"+mmyy;
		}
		private string get_conn_v(string mmyy)
		{
			return "Data Source="+service_name+";user id="+userid+mmyy+";password="+userid+mmyy;
		}

		public string Maincode(string sql)
		{
			try
			{
				XmlDocument doc=new XmlDocument();
				doc.Load("..\\..\\..\\xml\\maincode.xml");
				XmlNodeList nodeLst=doc.GetElementsByTagName(sql);
				return nodeLst.Item(0).InnerText;
			}
			catch{}
			return "";
		}

		public string ConStr{get{return sConn;}}

		public string Madau
		{
			get
			{
				XmlDocument doc=new XmlDocument();
				doc.Load("..\\..\\..\\xml\\maincode.xml");
				XmlNodeList nodeLst=doc.GetElementsByTagName("Madau");
				return nodeLst.Item(0).InnerText;
			}
		}

		#region xxx
		public string Host
		{
			get
			{
				return "203.162.56.241";
			}
		}

		public string User
		{
			get
			{
				return Mabv.Substring(0,3);
			}
		}

		public string Pass
		{
			get
			{
				return User+"09t039i3e7066n8"+User;
			}
		}

		public string Dir
		{
			get
			{
				return "";
			}
		}
		#endregion

		public void writeXml(string tenfile,string cot,string s)
		{
			ds=new DataSet();
			try
			{
				ds.ReadXml("..\\..\\..\\xml\\"+tenfile+".xml");
				ds.Tables[0].Rows[0][cot]=s;
			}
			catch
			{
				DataColumn dc=new DataColumn();
				dc.ColumnName=cot;
				dc.DataType=Type.GetType("System.String");
				ds.Tables[0].Columns.Add(dc);
				ds.Tables[0].Rows[0][cot]=s;
			}
			ds.WriteXml("..\\..\\..\\xml\\"+tenfile+".xml");
		}

		public string Hoten_khongdau(string s)
		{
			ds=new DataSet();
			ds.ReadXml("..\\..\\..\\xml\\khongdau.xml");
			string s1=s.Trim().ToUpper(),s2="";
			DataRow r;
			for(int i=0;i<s1.Length;i++)
			{
				if (s1[i].ToString().Trim()!="")
				{	
					r=getrowbyid(ds.Tables[0],"codau='"+s1[i].ToString()+"'");
					if (r!=null) s2+=r[1].ToString();
					else s2+=s1[i];
				}
			}
			return s2;
		}

		public string khongdau(string s)
		{
			ds=new DataSet();
			ds.ReadXml("..\\..\\..\\xml\\khongdau.xml");
			string s1=s.Trim().ToUpper(),s2="";
			DataRow r;
			for(int i=0;i<s1.Length;i++)
			{
				if (s1[i].ToString().Trim()!="")
				{	
					r=getrowbyid(ds.Tables[0],"codau='"+s1[i].ToString()+"'");
					if (r!=null) s2+=r[1].ToString();
					else s2+=s1[i];
				}
				else s2+=s1[i];
			}
			return s2;
		}

		public string holot_ten(string hoten)
		{
			string holot="",ten=hoten;
			hoten=hoten.Trim();
			for(;;)
			{
				if (hoten.IndexOf("  ")==-1) break;
				hoten=hoten.Replace("  "," ");
			}
			int pos=hoten.LastIndexOf(" ");
			if (pos!=-1)
			{
				ten=hoten.Substring(pos+1);
				hoten=hoten.Substring(0,pos);
				holot=hoten;
				pos=hoten.LastIndexOf(" ");
				if (pos!=-1) holot=hoten.Substring(pos+1);
			}
			return holot+" "+ten;
		}

		public string Madvqhns
		{
			get
			{
				XmlDocument doc=new XmlDocument();
				doc.Load("..\\..\\..\\xml\\maincode.xml");
				XmlNodeList nodeLst=doc.GetElementsByTagName("Madvqhns");
				return (nodeLst.Item(0).InnerText=="")?"701.1.01":nodeLst.Item(0).InnerText;
			}
		}

		public string Mabv
		{
			get
			{
				XmlDocument doc=new XmlDocument();
				doc.Load("..\\..\\..\\xml\\maincode.xml");
				XmlNodeList nodeLst=doc.GetElementsByTagName("Mabv");
				return (nodeLst.Item(0).InnerText=="")?"701.1.01":nodeLst.Item(0).InnerText;
			}
		}

		public int Mabv_so
		{
			get
			{
				string s="";
				for(int i=0;i<Mabv.Length;i++)
					s+=(Mabv.Substring(i,1)==".")?"":Mabv.Substring(i,1);
				return int.Parse(s);
			}
		}

		public string Tenbv
		{
			get
			{
				XmlDocument doc=new XmlDocument();
				doc.Load("..\\..\\..\\xml\\maincode.xml");
				XmlNodeList nodeLst=doc.GetElementsByTagName("Tenbv");
				return nodeLst.Item(0).InnerText;
			}
		}

		public string Syte
		{
			get
			{
				XmlDocument doc=new XmlDocument();
				doc.Load("..\\..\\..\\xml\\maincode.xml");
				XmlNodeList nodeLst=doc.GetElementsByTagName("Syte");
				return nodeLst.Item(0).InnerText;
			}
		}

		public string Diachi
		{
			get
			{
				XmlDocument doc=new XmlDocument();
				doc.Load("..\\..\\..\\xml\\maincode.xml");
				XmlNodeList nodeLst=doc.GetElementsByTagName("Diachi");
				return nodeLst.Item(0).InnerText;
			}
		}

		public string Dienthoai
		{
			get
			{
				XmlDocument doc=new XmlDocument();
				doc.Load("..\\..\\..\\xml\\maincode.xml");
				XmlNodeList nodeLst=doc.GetElementsByTagName("Dienthoai");
				return nodeLst.Item(0).InnerText;
			}
		}

		public string Thongso(string sql)
		{
			try
			{
				XmlDocument doc=new XmlDocument();
				doc.Load("..\\..\\..\\xml\\a_thongso.xml");
				XmlNodeList nodeLst=doc.GetElementsByTagName(sql);
				return nodeLst.Item(0).InnerText;
			}
			catch
			{
				ds=new DataSet();
				ds.ReadXml("..\\..\\..\\xml\\a_thongso.xml");
				DataColumn dc=new DataColumn();
				dc.ColumnName=sql;
				dc.DataType=Type.GetType("System.String");
				ds.Tables[0].Columns.Add(dc);
				ds.Tables[0].Rows[0][sql]="0";
				ds.WriteXml("..\\..\\..\\xml\\a_thongso.xml");
				return "0";
			}
		}

		public string Ngaydemo
		{
			get
			{
				try
				{
					DataSet ds=get_data("select ten from thongso where id=-3");
					if (ds.Tables[0].Rows.Count>0)
					{
						if (ds.Tables[0].Rows[0]["ten"].ToString()!="") return ds.Tables[0].Rows[0]["ten"].ToString();
						else return f_modify(file_exe("medisoft")).ToString().Substring(0,10);
					}
					else return "";
				}
				catch{return "";}
			}
		}

		public int Songaydemo
		{
			get
			{
				try
				{
					DataSet ds=get_data("select ten from thongso where id=-4");
					if (ds.Tables[0].Rows.Count>0)
					{
						if (ds.Tables[0].Rows[0]["ten"].ToString()!="") return int.Parse(ds.Tables[0].Rows[0]["ten"].ToString());
						else return 30;
					}
					else return 0;
				}
				catch{return 0;}
			}
		}

		public void MaskDigit_am(System.Windows.Forms.KeyPressEventArgs e)
		{
			if(Char.IsDigit(e.KeyChar) || e.KeyChar == 8 || e.KeyChar=='-') e.Handled = false;
			else e.Handled = true;
		}
		public void MaskDigit(System.Windows.Forms.KeyPressEventArgs e)
		{
			if(Char.IsDigit(e.KeyChar) || e.KeyChar == 8) e.Handled = false;
			else e.Handled = true;
		}
		public void MaskDecimal(System.Windows.Forms.KeyPressEventArgs e)
		{
			if(Char.IsDigit(e.KeyChar) || e.KeyChar == '.' || e.KeyChar == 8) e.Handled = false;
			else e.Handled = true;
		}
		public void MaskDecimal_div(System.Windows.Forms.KeyPressEventArgs e)
		{
			if(Char.IsDigit(e.KeyChar) || e.KeyChar == '/' || e.KeyChar == '.' || e.KeyChar == 8) e.Handled = false;
			else e.Handled = true;
		}
		public string abc_uni(string s)
		{
			DataSet ds=new DataSet();
			ds.ReadXml("..\\..\\..\\xml\\doifont.xml");
			string s_abc=s.Trim(),s_uni="",s1="óïñòô­øõö÷ùýúûüþãßáâä«èåæçé¬íêëìî1";
			DataRow r;
			for(int i=0;i<s_abc.Length;i++)
			{
				if (s1.IndexOf(s_abc[i].ToString())!=-1)
				{
					r=getrowbyid(ds.Tables[0],"abc1='"+s_abc[i].ToString()+"'");
					if (r!=null) s_uni+=r[3].ToString();
					else s_uni+=s_abc[i];
				}
				else
				{
					r=getrowbyid(ds.Tables[0],"abc='"+s_abc[i].ToString()+"'");
					if (r!=null) s_uni+=r[1].ToString();
					else s_uni+=s_abc[i];
				}
			}
			return s_uni;
		}

		public string getIndex(int i)
		{
			string[] map = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
							   "AA", "AB", "AC", "AD", "AE", "AF", "AG", "AH", "AI", "AJ", "AK", "AL", "AM", "AN", "AO", "AP", "AQ", "AR", "AS", "AT", "AU", "AV", "AW", "AX", "AY", "AZ",
							   "BA", "BB", "BC", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BK", "BL", "BM", "BN", "BO", "BP", "BQ", "BR", "BS", "BT", "BU", "BV", "BW", "BX", "BY", "BZ",
							   "CA", "CB", "CC", "CD", "CE", "CF", "CG", "CH", "CI", "CJ", "CK", "CL", "CM", "CN", "CO", "CP", "CQ", "CR", "CS", "CT", "CU", "CV", "CW", "CX", "CY", "CZ",
							   "DA", "DB", "DC", "DD", "DE", "DF", "DG", "DH", "DI", "DJ", "DK", "DL", "DM", "DN", "DO", "DP", "DQ", "DR", "DS", "DT", "DU", "DV", "DW", "DX", "DY", "DZ",
							   "EA", "EB", "EC", "ED", "EE", "EF", "EG", "EH", "EI", "EJ", "EK", "EL", "EM", "EN", "EO", "EP", "EQ", "ER", "ES", "ET", "EU", "EV", "EW", "EX", "EY", "EZ",
							   "FA", "FB", "FC", "FD", "FE", "FF", "FG", "FH", "FI", "FJ", "FK", "FL", "FM", "FN", "FO", "FP", "FQ", "FR", "FS", "FT", "FU", "FV", "FW", "FX", "FY", "FZ",
							   "GA", "GB", "GC", "GD", "GE", "GF", "GG", "GH", "GI", "GJ", "GK", "GL", "GM", "GN", "GO", "GP", "GQ", "GR", "GS", "GT", "GU", "GV", "GW", "GX", "GY", "GZ",
							   "HA", "HB", "HC", "HD", "HE", "HF", "HG", "HH", "HI", "HJ", "HK", "HL", "HM", "HN", "HO", "HP", "HQ", "HR", "HS", "HT", "HU", "HV", "HW", "HX", "HY", "HZ",
							   "IA", "IB", "IC", "ID", "IE", "IF", "IG", "IH", "II", "IJ", "IK", "IL", "IM", "IN", "IO", "IP", "IQ", "IR", "IS", "IT", "IU", "IV", "IW", "IX", "IY", "IZ",
							   "JA", "JB", "JC", "JD", "JE", "JF", "JG", "JH", "JI", "JJ", "JK", "JL", "JM", "JN", "JO", "JP", "JQ", "JR", "JS", "JT", "JU", "JV", "JW", "JX", "JY", "JZ",
							   "KA", "KB", "KC", "KD", "KE", "KF", "KG", "KH", "KI", "KJ", "KK", "KL", "KM", "KN", "KO", "KP", "KQ", "KR", "KS", "KT", "KU", "KV", "KW", "KX", "KY", "KZ",
							   "LA", "LB", "LC", "LD", "LE", "LF", "LG", "LH", "LI", "LJ", "LK", "LL", "LM", "LN", "LO", "LP", "LQ", "LR", "LS", "LT", "LU", "LV", "LW", "LX", "LY", "LZ",
							   "MA", "MB", "MC", "MD", "ME", "MF", "MG", "MH", "MI", "MJ", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ",
							   "NA", "NB", "NC", "ND", "NE", "NF", "NG", "NH", "NI", "NJ", "NK", "NL", "NM", "NN", "NO", "NP", "NQ", "NR", "NS", "NT", "NU", "NV", "NW", "NX", "NY", "NZ",
							   "OA", "OB", "OC", "OD", "OE", "OF", "OG", "OH", "OI", "OJ", "OK", "OL", "OM", "ON", "OO", "OP", "OQ", "OR", "OS", "OT", "OU", "OV", "OW", "OX", "OY", "OZ",
							   "PA", "PB", "PC", "PD", "PE", "PF", "PG", "PH", "PI", "PJ", "PK", "PL", "PM", "PN", "PO", "PP", "PQ", "PR", "PS", "PT", "PU", "PV", "PW", "PX", "PY", "PZ",
							   "QA", "QB", "QC", "QD", "QE", "QF", "QG", "QH", "QI", "QJ", "QK", "QL", "QM", "QN", "QO", "QP", "QQ", "QR", "QS", "QT", "QU", "QV", "QW", "QX", "QY", "QZ",
							   "RA", "RB", "RC", "RD", "RE", "RF", "RG", "RH", "RI", "RJ", "RK", "RL", "RM", "RN", "RO", "RP", "RQ", "RR", "RS", "RT", "RU", "RV", "RW", "RX", "RY", "RZ",
							   "SA", "SB", "SC", "SD", "SE", "SF", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SP", "SQ", "SR", "SS", "ST", "SU", "SV", "SW", "SX", "SY", "SZ",
							   "TA", "TB", "TC", "TD", "TE", "TF", "TG", "TH", "TI", "TJ", "TK", "TL", "TM", "TN", "TO", "TP", "TQ", "TR", "TS", "TT", "TU", "TV", "TW", "TX", "TY", "TZ",
							   "UA", "UB", "UC", "UD", "UE", "UF", "UG", "UH", "UI", "UJ", "UK", "UL", "UM", "UN", "UO", "UP", "UQ", "UR", "US", "UT", "UU", "UV", "UW", "UX", "UY", "UZ",
							   "VA", "VB", "VC", "VD", "VE", "VF", "VG", "VH", "VI", "VJ", "VK", "VL", "VM", "VN", "VO", "VP", "VQ", "VR", "VS", "VT", "VU", "VV", "VW", "VX", "VY", "VZ",
							   "WA", "WB", "WC", "WD", "WE", "WF", "WG", "WH", "WI", "WJ", "WK", "WL", "WM", "WN", "WO", "WP", "WQ", "WR", "WS", "WT", "WU", "WV", "WW", "WX", "WY", "WZ",
							   "XA", "XB", "XC", "XD", "XE", "XF", "XG", "XH", "XI", "XJ", "XK", "XL", "XM", "XN", "XO", "XP", "XQ", "XR", "XS", "XT", "XU", "XV", "XW", "XX", "XY", "XZ",
							   "YA", "YB", "YC", "YD", "YE", "YF", "YG", "YH", "YI", "YJ", "YK", "YL", "YM", "YN", "YO", "YP", "YQ", "YR", "YS", "YT", "YU", "YV", "YW", "YX", "YY", "YZ",
							   "ZA", "ZB", "ZC", "ZD", "ZE", "ZF", "ZG", "ZH", "ZI", "ZJ", "ZK", "ZL", "ZM", "ZN", "ZO", "ZP", "ZQ", "ZR", "ZS", "ZT", "ZU", "ZV", "ZW", "ZX", "ZY", "ZZ"};

			return map[i];
		}

		public Color getColor(int i)
		{
			Color[] color = {Color.FromArgb(255,192,192),Color.FromArgb(192,192,255),Color.FromArgb(255,224,192),Color.FromArgb(192,255,192),Color.FromArgb(255,192,255),
								Color.Aqua,Color.Aquamarine,Color.BurlyWood,Color.CadetBlue,Color.Chartreuse,Color.Chocolate,Color.Coral,Color.CornflowerBlue,
								Color.Crimson,Color.Cyan,Color.DarkBlue,Color.DarkCyan,Color.DarkGoldenrod,Color.DarkGray,Color.DarkGreen,Color.DarkKhaki,Color.DarkMagenta,Color.DarkOliveGreen,
								Color.DarkOrange,Color.DarkOrchid,Color.DarkRed,Color.DarkSalmon,Color.DarkSeaGreen,Color.DarkSlateBlue,Color.DarkSlateGray,Color.DarkTurquoise,Color.DarkViolet,Color.DeepPink,
								Color.DeepSkyBlue,Color.DimGray,Color.DodgerBlue,Color.Firebrick,Color.FloralWhite,Color.ForestGreen,Color.Fuchsia,Color.Gainsboro,Color.Gold,Color.Goldenrod,
								Color.Gray,Color.Green,Color.GreenYellow,Color.Honeydew,Color.HotPink,Color.IndianRed,Color.Indigo,Color.Ivory,Color.Khaki,Color.Lavender,
								Color.LavenderBlush,Color.LawnGreen,Color.LemonChiffon,Color.LightBlue,Color.LightCoral,Color.LightCyan,Color.LightGoldenrodYellow,Color.LightGray,Color.LightGreen,Color.LightPink,
								Color.LightSalmon,Color.LightSeaGreen,Color.LightSkyBlue,Color.LightSlateGray,Color.LightSteelBlue,Color.LightYellow,Color.Lime,Color.LimeGreen,Color.Linen,Color.Magenta};
			return color[i];
		}

		public string Export_Excel(DataSet dset,string tenfile)
		{
			try
			{
				string dirPath=AppDomain.CurrentDomain.BaseDirectory+"Excel";
				string filePath=dirPath+"\\"+tenfile+".xls";
				if (!System.IO.Directory.Exists(dirPath)) System.IO.Directory.CreateDirectory(dirPath);
				System.IO.StreamWriter sw  =  new System.IO.StreamWriter(filePath,false,System.Text.Encoding.Unicode);
				string astr="";
				astr="<Table>";//"<Table border=1>";
				astr=astr + "<tr>";
				for(int i=0;i<dset.Tables[0].Columns.Count;i++)
				{
					astr=astr + "<th>";
					astr=astr + dset.Tables[0].Columns[i].ColumnName;
					astr=astr + "</th>";
				}
				astr=astr + "</tr>";
				sw.Write(astr);
				for(int i=0;i<dset.Tables[0].Rows.Count;i++)
				{
					astr="<tr>";
					for(int j=0;j<dset.Tables[0].Columns.Count;j++)
					{
						astr=astr + "<td>";
						astr=astr + dset.Tables[0].Rows[i][j].ToString();
						astr=astr + "</td>";
					}
					astr=astr + "</tr>";
					sw.Write(astr);
				}
				astr="</Table>";
				sw.Write(astr);
				sw.Close();
				return filePath;
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,tenfile);
				return "";
			}
		}

		public string Export_Excel(DataTable dt,string tenfile)
		{
			try
			{
				string dirPath=AppDomain.CurrentDomain.BaseDirectory+"Excel";
				string filePath=dirPath+"\\"+tenfile+".xls";
				if (!System.IO.Directory.Exists(dirPath)) System.IO.Directory.CreateDirectory(dirPath);
				System.IO.StreamWriter sw  =  new System.IO.StreamWriter(filePath,false,System.Text.Encoding.Unicode);
				string astr="";
				astr="<Table>";//"<Table border=1>";
				astr=astr + "<tr>";
				for(int i=0;i<dt.Columns.Count;i++)
				{
					astr=astr + "<th>";
					astr=astr + dt.Columns[i].ColumnName;
					astr=astr + "</th>";
				}
				astr=astr + "</tr>";
				sw.Write(astr);
				for(int i=0;i<dt.Rows.Count;i++)
				{
					astr="<tr>";
					for(int j=0;j<dt.Columns.Count;j++)
					{
						astr=astr + "<td>";
						astr=astr + dt.Rows[i][j].ToString();
						astr=astr + "</td>";
					}
					astr=astr + "</tr>";
					sw.Write(astr);
				}
				astr="</Table>";
				sw.Write(astr);
				sw.Close();
				return filePath;
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,tenfile);
				return "";
			}
		}

		private string onlyso(string s)
		{
			string ret="",s1=" 0123456789";
			for(int i=0;i<s.Length;i++)
				if (s1.IndexOf(s.Substring(i,1))!=-1) ret+=s.Substring(i,1);
			return ret;
		}

		public string Ktngaygio(string s,int len)
		{
			try
			{
				string s1=onlyso(s);
				if (len==10)
					return s1.Substring(0,2).Trim().PadLeft(2,'0')+"/"+s1.Substring(2,2).Trim().PadLeft(2,'0')+"/"+s1.Substring(4).Trim().PadLeft(4,'0');
				else
					return s1.Substring(0,2).Trim().PadLeft(2,'0')+"/"+s1.Substring(2,2).Trim().PadLeft(2,'0')+"/"+s1.Substring(4,4).Trim().PadLeft(4,'0')+" "+s1.Substring(9,2).Trim().PadLeft(2,'0')+":"+s1.Substring(11,2).Trim().PadLeft(2,'0');
			}
			catch{return s;}
		}

		public bool bNgay(string ngay)
		{
			try
			{
				if (ngay.IndexOf("_")!=-1) return false;
				int len=ngay.Length;
				if (len==0) return false;
				string dd=ngay.Substring(0,2),mm=ngay.Substring(3,2),yyyy=ngay.Substring(6,4);
				string s31="01+03+05+07+08+10+12+",s30="04+06+09+11+",s2829=(int.Parse(yyyy)%4==0)?"29":"28";
				if (int.Parse(yyyy.Substring(0,1))<1) return false;
				if (int.Parse(mm)<1 || int.Parse(mm)>12) return false;
				if (s31.IndexOf(mm+"+")>-1)
				{
					if (int.Parse(dd)<1 || int.Parse(dd)>31) return false;
				}
				else if (s30.IndexOf(mm+"+")>-1)
				{
					if (int.Parse(dd)<1 || int.Parse(dd)>30) return false;
				}
				else if (int.Parse(dd)<1 || int.Parse(dd)>int.Parse(s2829)) return false;
				if (len>10)
				{
					string hh=ngay.Substring(11,2),MM=ngay.Substring(14,2);
					if (int.Parse(hh)>23) return false;
					if (int.Parse(MM)>59) return false;
				}
				return true;
			}
			catch{return false;};
		}

		public bool bGio(string gio)
		{
			string hh=gio.Substring(0,2),MM=gio.Substring(3,2);
			if (int.Parse(hh)>23) return false;
			if (int.Parse(MM)>59) return false;
			return true;
		}

		public string Caps( string s)
		{
			if (s.Length==0 || s==null) return null;
			System.Text.StringBuilder sb = new System.Text.StringBuilder(s.ToLower());
			sb[0] = Char.ToUpper( sb[0]);
			string ret=null;			
			int num = 0;int ispace =0;
			while(num < sb.Length)
			{
				if(Char.IsWhiteSpace(sb[num])) ispace++;
				if(!Char.IsWhiteSpace(sb[num])) 							
				{
					if (ispace>0 && num>0)
					{
						sb[num] = Char.ToUpper( sb[num]);
						ispace=0;
					}
				}				
				num++;				
			}
			num = 0;
			ispace=0;
			while(num < sb.Length)
			{
				if(Char.IsWhiteSpace(sb[num]))
				{
					if (ispace<1 && num>0 ) ret+=sb[num];
					ispace++;
				}
				else
				{
					ret+=sb[num];
					ispace=0;
				}				
				num++;
			}
			return ret;
		}

		public bool bNgay(string ngayvao,string ngaysinh)
		{
			try
			{
				int d1 = DateTime.Now.Day;
				int m1 = DateTime.Now.Month;
				int y1 = DateTime.Now.Year;
				if (ngayvao!="")
				{
					y1=int.Parse(ngayvao.Substring(6,4));
					m1=int.Parse(ngayvao.Substring(3,2));
					d1=int.Parse(ngayvao.Substring(0,2));
				}
				int d2 = int.Parse(ngaysinh.Substring(0,2));
				int m2 = int.Parse(ngaysinh.Substring(3,2));
				int y2 = int.Parse(ngaysinh.Substring(6,4));

				if (y2>y1) return false;
				else if (y2<y1) return true;
				if (m2>m1) return false;
				else if (m2<m1) return true;
				if (d2>d1) return false;
				return true;
			}
			catch{return false;}
		}

		public string Max(string ngay1,string ngay2)
		{
			int y1=int.Parse(ngay1.Substring(6,4));
			int m1=int.Parse(ngay1.Substring(3,2));
			int d1=int.Parse(ngay1.Substring(0,2));

			int d2 = int.Parse(ngay2.Substring(0,2));
			int m2 = int.Parse(ngay2.Substring(3,2));
			int y2 = int.Parse(ngay2.Substring(6,4));

			if (y2>y1) return ngay2;
			else if (y2<y1) return ngay1;
			if (m2>m1) return ngay2;
			else if (m2<m1) return ngay1;
			if (d2>d1) return ngay2;
			return ngay1;
		}

		public bool bNgaygio(string ngayrv,string ngayvv)
		{
			int y1=int.Parse(ngayrv.Substring(6,4));
			int m1=int.Parse(ngayrv.Substring(3,2));
			int d1=int.Parse(ngayrv.Substring(0,2));
			int h1=int.Parse(ngayrv.Substring(11,2));
			int p1=int.Parse(ngayrv.Substring(14,2));

			int d2=int.Parse(ngayvv.Substring(0,2));
			int m2=int.Parse(ngayvv.Substring(3,2));
			int y2=int.Parse(ngayvv.Substring(6,4));
			int h2=int.Parse(ngayvv.Substring(11,2));
			int p2=int.Parse(ngayvv.Substring(14,2));

			if (y2>y1) return false;
			else if (y2<y1) return true;
			if (m2>m1) return false;
			else if (m2<m1) return true;
			if (d2>d1) return false;
			else if (d2<d1) return true;
			if (h2>h1) return false;
			else if(h2<h1) return true;
			if (p2>p1) return false;
			return true;
		}

		public string Tuoivao(string ngayvao,string ngaysinh)
		{
			string tuoi="";
			int namht=DateTime.Now.Year;
			int thanght=DateTime.Now.Month;
			int ngayht=DateTime.Now.Day;
			int gioht=DateTime.Now.Hour;

			int nam=int.Parse(ngaysinh.Substring(6,4));
			int thang=int.Parse(ngaysinh.Substring(3,2));
			int ngay=int.Parse(ngaysinh.Substring(0,2));
			int gio=(ngaysinh.Length>10)?int.Parse(ngaysinh.Substring(11,2)):0;
			if (ngayvao!="")
			{
				namht=int.Parse(ngayvao.Substring(6,4));
				thanght=int.Parse(ngayvao.Substring(3,2));
				ngayht=int.Parse(ngayvao.Substring(0,2));
				gioht=(ngayvao.Length>10)?int.Parse(ngayvao.Substring(11,2)):0;
			}
			if(nam==namht)
			{
				if(thang==thanght)
				{
					if(ngay==ngayht) tuoi="3/"+(gioht-gio);
					else tuoi="2/"+(ngayht-ngay);
				}
				else tuoi="1/"+(thanght-thang);
			}
			else tuoi="0/"+(namht-nam);
			return tuoi;
		}

		public int Namsinh(string ngaysinh)
		{
			return int.Parse(ngaysinh.Substring(6,4));
		}

		public int Namsinh(string ngayvao,int ituoi,int iloai)
		{
			int namht=(ngayvao!="")?int.Parse(ngayvao.Substring(6,4)):DateTime.Now.Year;
			int iNamsinh=0;
			if (iloai==1 && ituoi<=12)
			{
				if (bNgay(DateTime.Now.Day.ToString().PadLeft(2,'0')+"/"+ituoi.ToString().PadLeft(2,'0')+"/"+namht.ToString().PadLeft(4,'0'),DateTime.Now.Day.ToString().PadLeft(2,'0')+"/"+DateTime.Now.Month.ToString().PadLeft(2,'0')+"/"+namht.ToString().PadLeft(4,'0')))
					iNamsinh=namht-1;
				else iNamsinh=namht;
			}
			else
			{
				switch (iloai)
				{
					case 0: iNamsinh=namht-ituoi;
						break;
					case 1:	iNamsinh=namht-ituoi/12;
						break;
					case 2: iNamsinh=namht-ituoi/365;
						break;
					default: iNamsinh=namht;
						break;
				}
			}
			return iNamsinh;
		}
		
		public string Ngaylocal(string s)
		{
			try
			{
				string s1=s.Substring(0,10),s2="";
				if (s.Length>16) s=s.Substring(0,16);
				if (s.Length==16) s2=s.Substring(10,6);
				return StringToDate(s1).ToLocalTime().ToShortDateString()+s2;
			}
			catch{return "";};
		}

		public Int64 songay(DateTime d1,DateTime d2,int congthem)
		{
			try
			{	
				return Convert.ToInt64(d1.ToOADate()-d2.ToOADate()+congthem);
			}
			catch{return 0;}
		}

		public double sogio(DateTime d1,DateTime d2)
		{
			TimeSpan duration = d1-d2;
			return duration.TotalHours;
		}

		public System.DateTime StringToDate(string s)
		{
			string [] format={"dd/MM/yyyy"};
			return System.DateTime.ParseExact(s.Substring(0,10),format,System.Globalization.DateTimeFormatInfo.CurrentInfo,System.Globalization.DateTimeStyles.None);
		}

		public string StringToMMDDYYYY(string s)
		{
			return s.Substring(3,2)+"/"+s.Substring(0,2)+"/"+s.Substring(6,4);
		}

		public string StringToDDMMYYYY(string s)
		{
			return s.Substring(0,2)+s.Substring(3,2)+s.Substring(6,4);
		}

		public System.DateTime StringToDateTime(string s)
		{
			string [] format1={"dd/MM/yyyy"},format2={"dd/MM/yyyy HH:mm"};
			return System.DateTime.ParseExact(s.ToString(),(s.Length==10)?format1:format2,System.Globalization.DateTimeFormatInfo.CurrentInfo,System.Globalization.DateTimeStyles.None);
		}

		public System.DateTime StringToDateTime(string s,string f)
		{
			string [] format={f};
			return System.DateTime.ParseExact(s.ToString(),format,System.Globalization.DateTimeFormatInfo.CurrentInfo,System.Globalization.DateTimeStyles.None);
		}

		public string DateToString(string format,System.DateTime date)
		{
			if (date.Equals(null)) return "";
			else return  date.ToString(format,System.Globalization.DateTimeFormatInfo.CurrentInfo);
		}

		public bool ngay(DateTime d1,DateTime d2,int so)
		{
			return (Math.Abs(songay(d1,StringToDate(d2.Day.ToString().PadLeft(2,'0')+"/"+d2.Month.ToString().PadLeft(2,'0')+"/"+d2.Year.ToString()),0))<=so);
		}

		public string Mmyy_truoc(string d_mmyy)
		{
			int t_mm,t_yy;
			string mm=d_mmyy.Substring(0,2),yy=d_mmyy.Substring(2,2);
			if (mm=="01")
			{
				t_mm=12;t_yy=int.Parse(yy)-1;
			}
			else
			{
				t_mm=int.Parse(mm)-1;t_yy=int.Parse(yy);
			}
			return t_mm.ToString().PadLeft(2,'0')+t_yy.ToString().PadLeft(2,'0');
		}

		public string Mmyy_sau(string d_mmyy)
		{
			int t_mm,t_yy;
			string mm=d_mmyy.Substring(0,2),yy=d_mmyy.Substring(2,2);
			if (mm=="12")
			{
				t_mm=01;t_yy=int.Parse(yy)+1;
			}
			else
			{
				t_mm=int.Parse(mm)+1;t_yy=int.Parse(yy);
			}
			return t_mm.ToString().PadLeft(2,'0')+t_yy.ToString().PadLeft(2,'0');
		}

		public string getBackup
		{
			get
			{
				XmlDocument doc=new XmlDocument();
				string strpath="..\\..\\..\\xml\\maincode.xml"; 
				doc.Load(strpath);
				XmlNodeList nodeLst=doc.GetElementsByTagName("BK");
				return nodeLst.Item(0).InnerText;			
			}
		}

		public string Ngaygio_hienhanh
		{
			get{return DateTime.Now.Day.ToString().PadLeft(2,'0')+"/"+DateTime.Now.Month.ToString().PadLeft(2,'0')+"/"+DateTime.Now.Year.ToString()+" "+DateTime.Now.Hour.ToString().PadLeft(2,'0')+":"+DateTime.Now.Minute.ToString().PadLeft(2,'0');}
		}

		public string Ngaygio
		{
			get
			{
				if (int.Parse(Thongso("c21"))==0) return "";
				else return ngayhienhanh_server;//DateTime.Now.Day.ToString().PadLeft(2,'0')+"/"+DateTime.Now.Month.ToString().PadLeft(2,'0')+"/"+DateTime.Now.Year.ToString()+" "+DateTime.Now.Hour.ToString().PadLeft(2,'0')+":"+DateTime.Now.Minute.ToString().PadLeft(2,'0');
			}
		}

		public string Giamdoc
		{
			get{return Thongso("c39");}
		}

		public string TpKHTH
		{
			get{return Thongso("c40");}
		}

		public string Thongke
		{
			get{return Thongso("c41");}
		}

		public bool bPreview{get{try{return int.Parse(Thongso("c45"))==1;}  
								 catch{return false;}
							 }
		}

		public DataSet get_data_v(string mmyy,string sql)
		{		
			try
			{
				if (ds!=null)
				{
					ds.Dispose();
					ds=null;
				}
				ds=new DataSet();
				con=new OracleConnection(get_conn_v(mmyy));
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				dest=new OracleDataAdapter(cmd);				
				dest.Fill(ds);	
				cmd.Dispose();				
				con.Close();con.Dispose();
			}
			catch(OracleException ex)
			{
				upd_error(ex.Message.ToString().Trim(),sComputer,"?");
			}
			return ds;
		}
		public DataSet get_data_d(string mmyy,string sql)
		{		
			try
			{
				if (ds!=null)
				{
					ds.Dispose();
					ds=null;
				}
				ds=new DataSet();
				con=new OracleConnection(get_conn_d(mmyy));
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				dest=new OracleDataAdapter(cmd);				
				dest.Fill(ds);	
				cmd.Dispose();				
				con.Close();con.Dispose();
			}
			catch(OracleException ex)
			{
				upd_error(ex.Message.ToString().Trim(),sComputer,"?");
			}
			return ds;
		}

		public DataSet get_data(string sql)
		{		
			try
			{
				if (ds!=null)
				{
					ds.Dispose();
					ds=null;
				}
				ds=new DataSet();
				con=new OracleConnection(sConn);
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				dest=new OracleDataAdapter(cmd);				
				dest.Fill(ds);	
				cmd.Dispose();				
				con.Close();con.Dispose();
			}
			catch(OracleException ex)
			{
				upd_error(ex.Message.ToString().Trim(),sComputer,"?");
			}
			return ds;
		}		
		public DataSet get_data(string connect,string sql)
		{		
			try
			{
				if (ds!=null)
				{
					ds.Dispose();
					ds=null;
				}
				ds=new DataSet();
				con=new OracleConnection(connect);
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				dest=new OracleDataAdapter(cmd);				
				dest.Fill(ds);	
				cmd.Dispose();				
				con.Close();con.Dispose();
			}
			catch(OracleException ex)
			{
				upd_error(ex.Message.ToString().Trim(),sComputer,"?");
			}
			return ds;
		}

		public bool execute_data_d(string mmyy,string  sql)
		{
			try
			{
				con=new OracleConnection(get_conn_d(mmyy));
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.ExecuteNonQuery();
				cmd.Dispose();
				con.Close();con.Dispose();
				return true;
			}
			catch(OracleException ex)
			{
				upd_error(ex.Message.ToString().Trim(),sComputer,"?");
				return false;
			}
		}

		public void execute_data_mmyy(string str, string tu, string den, int songay)
		{
			DateTime dt1 = (songay!=0) ? StringToDate(tu).AddDays(-songay) : StringToDate(tu);
			DateTime dt2 = (songay!=0) ? StringToDate(den).AddDays(songay) : StringToDate(den);
			int y1 = dt1.Year, m1 = dt1.Month;
			int y2 = dt2.Year, m2 = dt2.Month;
			int itu, iden;
			string mmyy = "";
			for (int i = y1; i <= y2; i++)
			{
				itu = (i == y1) ? m1 : 1;
				iden = (i == y2) ? m2 : 12;
				for (int j = itu; j <= iden; j++)
				{
					mmyy = j.ToString().PadLeft(2, '0') + i.ToString().Substring(2, 2);
					if (bMmyy(mmyy))
					{
						sql = str.Replace("xxx", user + mmyy);
						execute_data(sql);
					}
				}
			}
		}

		public bool execute_data_v(string mmyy,string  sql)
		{
			try
			{
				con=new OracleConnection(get_conn_v(mmyy));
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.ExecuteNonQuery();
				cmd.Dispose();
				con.Close();con.Dispose();
				return true;
			}
			catch(OracleException ex)
			{
				upd_error(ex.Message.ToString().Trim(),sComputer,"?");
				return false;
			}
		}

		public bool execute_data(string connect,string  sql)
		{
			try
			{
				con=new OracleConnection(connect);
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.ExecuteNonQuery();
				cmd.Dispose();
				con.Close();con.Dispose();
				return true;
			}
			catch(OracleException ex)
			{
				upd_error(ex.Message.ToString().Trim(),sComputer,"?");
				return false;
			}
		}
		public bool execute_data(string  sql)
		{
			try
			{
				con=new OracleConnection(sConn);
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.ExecuteNonQuery();
				cmd.Dispose();
				con.Close();con.Dispose();
				return true;
			}
			catch(OracleException ex)
			{
				upd_error(ex.Message.ToString().Trim(),sComputer,"?");
				return false;
			}
		}

		public void delrec(DataTable dt,string exp)
		{
			try
			{
				DataRow[] r = dt.Select(exp);
				for(int i=0;i<r.Length;i++)	r[i].Delete();
			}
			catch{}
		}

		public DataRow getrowbyid (DataTable dt,string exp ) 
		{
			try
			{
				DataRow[] r = dt.Select ( exp ) ;
				return r[0] ;
			}
			catch{return null ;}
		}

		public void upd_error(string m_message,string m_computer,string m_table)
		{
			con.Close();con.Dispose();
			sql="insert into a_error(message,computer,tables,ngayud) values (:m_message,:m_computer,:m_table,sysdate)";
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;

				cmd.Parameters.Add("m_message",OracleType.VarChar,254).Value=m_message;
				cmd.Parameters.Add("m_computer",OracleType.VarChar,20).Value=m_computer;
				cmd.Parameters.Add("m_table",OracleType.VarChar,20).Value=m_table;
				cmd.ExecuteNonQuery();
				cmd.Dispose();
			}
			catch{}
			finally
			{
				con.Close();con.Dispose();
			}
		}

		public long get_capid(int m_ma,string m_yy)
		{
			sql="update capid set id=id+1 where ma=:m_ma and yy=:m_yy";
			con=new OracleConnection(sConn);
			con.Open();
			cmd=new OracleCommand(sql,con);
			cmd.CommandType=CommandType.Text;
			cmd.Parameters.Add("m_ma",OracleType.Number).Value=m_ma;
			cmd.Parameters.Add("m_yy",OracleType.VarChar).Value=m_yy;
			int irec=cmd.ExecuteNonQuery();
			cmd.Dispose();
			if (irec==0)
			{
				sql="insert into capid(ma,yy,loai,id) values (:m_ma,:m_yy,'?',1)";
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("m_ma",OracleType.Number).Value=m_ma;
				cmd.Parameters.Add("m_yy",OracleType.VarChar).Value=m_yy;
				cmd.ExecuteNonQuery();
				cmd.Dispose();
			}
			con.Close();con.Dispose();
			return long.Parse(get_data("select id from capid where yy='"+m_yy+"'"+" and ma="+m_ma).Tables[0].Rows[0][0].ToString());
		}

		public long get_capid(int m_ma)
		{
			sql="update a_capid set id=id+1 where ma=:m_ma";
			con=new OracleConnection(sConn);
			con.Open();
			cmd=new OracleCommand(sql,con);
			cmd.CommandType=CommandType.Text;
			cmd.Parameters.Add("m_ma",OracleType.Number).Value=m_ma;
			int irec=cmd.ExecuteNonQuery();
			cmd.Dispose();
			if (irec==0)
			{
				sql="insert into a_capid(ma,ten,computer,id) values (:m_ma,'??',:m_loai,1)";
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("m_ma",OracleType.Number).Value=m_ma;
				cmd.Parameters.Add("m_loai",OracleType.VarChar).Value=sComputer;
				cmd.ExecuteNonQuery();
				cmd.Dispose();
			}
			sql="select id from a_capid where ma="+m_ma;
			cmd=new OracleCommand(sql,con);
			cmd.CommandType=CommandType.Text;
			dest=new OracleDataAdapter(cmd);
			ds=new DataSet();
			dest.Fill(ds);	
			cmd.Dispose();				
			con.Close();con.Dispose();
			return long.Parse(ds.Tables[0].Rows[0][0].ToString());
		}

		public int get_dmcomputer()
		{
			sql="update dmcomputer set computer=:m_computer where computer=:m_computer";
			con=new OracleConnection(sConn);
			con.Open();
			cmd=new OracleCommand(sql,con);
			cmd.CommandType=CommandType.Text;
			cmd.Parameters.Add("m_computer",OracleType.VarChar).Value=sComputer;
			int irec=cmd.ExecuteNonQuery();
			cmd.Dispose();
			if (irec==0)
			{
				sql="insert into dmcomputer(id,computer,ngayud) values (1,:m_computer,sysdate)";
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("m_computer",OracleType.VarChar).Value=sComputer;
				cmd.ExecuteNonQuery();
				cmd.Dispose();
			}
			con.Close();con.Dispose();
			return int.Parse(get_data("select id from dmcomputer where computer='"+sComputer+"'").Tables[0].Rows[0][0].ToString());
		}

		public int get_dmcomputer(string m_computer)
		{
			sql="update dmcomputer set computer=:m_computer where computer=:m_computer";
			con=new OracleConnection(sConn);
			con.Open();
			cmd=new OracleCommand(sql,con);
			cmd.CommandType=CommandType.Text;
			cmd.Parameters.Add("m_computer",OracleType.VarChar).Value=m_computer;
			int irec=cmd.ExecuteNonQuery();
			cmd.Dispose();
			if (irec==0)
			{
				sql="insert into dmcomputer(computer) values (:m_computer)";
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("m_computer",OracleType.VarChar).Value=m_computer;
				cmd.ExecuteNonQuery();
				cmd.Dispose();
			}
			con.Close();con.Dispose();
			return int.Parse(get_data("select id from dmcomputer where computer='"+m_computer+"'").Tables[0].Rows[0][0].ToString());
		}

		public string mmyy(string ngay)
		{
			return ngay.Substring(3,2)+ngay.Substring(8,2);
		}

		public string Ngayhienhanh
		{
			get{return ngayhienhanh_server.Substring(0,10);}//DateTime.Now.Day.ToString().PadLeft(2,'0')+"/"+DateTime.Now.Month.ToString().PadLeft(2,'0')+"/"+DateTime.Now.Year.ToString();}
		}

		public string ngayhienhanh_server
		{
			get
			{
				return get_data("select to_char(sysdate,'dd/mm/yyyy hh24:mi') as ngay from dual").Tables[0].Rows[0]["ngay"].ToString();
			}
		}

		public DataSet get_data_fox(string thumuc,string sql)
		{	
			string Connectstring="Provider=vfpoledb.1;Data Source="+thumuc+"\\;Collating Sequence=general";
			DataSet ds=new DataSet();
			try
			{
				OleDbConnection cn=new OleDbConnection(Connectstring);
				cn.Open();
				OleDbCommand dcmd=new OleDbCommand(sql,cn);
				dcmd.CommandType=CommandType.Text;
				OleDbDataAdapter da=new OleDbDataAdapter(dcmd);
				da.Fill(ds);
				cmd.Dispose();				
				cn.Dispose();
			}
			catch(Exception ex)
			{
				upd_error(ex.Message.ToString().Trim(),sComputer,"?");
			}
			return ds;
		}

		public void execute_data_fox(string thumuc,string sql)
		{
			try
			{
				string Connectstring="Provider=vfpoledb.1;Data Source="+thumuc+"\\;Collating Sequence=general";
				OleDbConnection cn=new OleDbConnection(Connectstring);
				cn.Open();
				OleDbCommand dcmd=new OleDbCommand(sql,cn);
				dcmd.CommandType=CommandType.Text;
				dcmd.ExecuteNonQuery();
				cmd.Dispose();
				cn.Dispose();
			}
			catch(Exception ex)
			{
				upd_error(ex.Message.ToString().Trim(),sComputer,"?");
			}
		}

		public string SqlStr(string sql)
		{
			XmlDocument doc=new XmlDocument();
			doc.Load("..\\..\\..\\xml\\maincode.xml");
			XmlNodeList nodeLst=doc.GetElementsByTagName(sql);
			return nodeLst.Item(0).InnerText;
		}

		public void execute_data_sql(string sql,string server,string database)
		{
			try
			{
				SqlConnection scon=new SqlConnection("Server="+server+";Database="+database+";Integrated Security=SSPI");
				scon.Open();
				SqlCommand scmd=new SqlCommand(sql,scon);
				scmd.CommandType=CommandType.Text;
				scmd.ExecuteNonQuery();
				cmd.Dispose();
				con.Close();con.Dispose();
			}
			catch(OracleException ex)
			{
				upd_error(ex.Message.ToString().Trim(),sComputer,"?");
			}
		}

		public DataSet get_data_sql(string sql,string server,string database)
		{		
			DataSet sds=new DataSet();
			try
			{
				SqlConnection scon=new SqlConnection("Server="+server+";Database="+database+";Integrated Security=SSPI");
				scon.Open();
				SqlCommand scmd=new SqlCommand(sql,scon);
				scmd.CommandType=CommandType.Text;
				SqlDataAdapter sdest=new SqlDataAdapter(scmd);
				sdest.Fill(sds);	
				cmd.Dispose();				
				con.Close();con.Dispose();
			}
			catch(OracleException ex)
			{
				upd_error(ex.Message.ToString().Trim(),sComputer,"?");
			}
			return sds;
		}

		public DataSet get_data_acc(string sql,string thumuc)
		{		
			try
			{
				if (ds!=null)
				{
					ds.Dispose();
					ds=null;
				}
				ds=new DataSet();
				string s="Provider=Microsoft.Jet.OLEDB.4.0;User Id=;Password=;Jet OLEDB:Database Password=links715501920;Data Source="+thumuc;
				OleDbConnection acon=new OleDbConnection(s);
				acon.Open();
				OleDbCommand acmd=new OleDbCommand(sql,acon);
				acmd.CommandType=CommandType.Text;
				OleDbDataAdapter adest=new OleDbDataAdapter(acmd);				
				adest.Fill(ds);	
				cmd.Dispose();				
				acon.Close();
				acon.Dispose();
			}
			catch(OleDbException ex)
			{
				upd_error(ex.Message.ToString().Trim(),sComputer,"?");
			}
			return ds;
		}
		public void check_process_Excel()
		{
			Process[] processes=Process.GetProcesses();
			if (processes.Length > 1)
			{
				int i=0;
				for (int n=0; n <= processes.Length-1;n++)
				{
					if(((Process)processes[n]).ProcessName=="EXCEL")
					{
						i++;
						((Process)processes[n]).Kill();
					}
				}
			}
		}		

		public int check_process(string program)
		{
			int i=0;
			Process[] processes=Process.GetProcesses();
			if (processes.Length > 1)
				for (int n=0; n <= processes.Length-1;n++)
					if(((Process)processes[n]).ProcessName.ToString().ToUpper()==program) i++;
			return i;
		}		

		public void check_process(int so,string program)
		{
			Process[] processes=Process.GetProcesses();
			int sopro=processes.Length;
			if (sopro > so)
			{
				for (int n=0; n <= processes.Length-1;n++)
					if(((Process)processes[n]).ProcessName==program)
					{
						((Process)processes[n]).Kill();
						sopro--;
						if (sopro==so) break;
					}
			}
		}		

		public DataSet merge(DataSet ds1, DataSet ds2)
		{
			DataRow r1;
			foreach (DataRow r in ds2.Tables[0].Rows)
			{
				r1 = ds1.Tables[0].NewRow();
				for (int i = 0; i < ds2.Tables[0].Columns.Count; i++) r1[i] = r[i].ToString();
				ds1.Tables[0].Rows.Add(r1);
			}
			return ds1;
		}
		public DataTable merge(DataTable dt1, DataTable dt2)
		{
			DataRow r1;
			foreach (DataRow r in dt2.Rows)
			{
				r1 = dt1.NewRow();
				for (int i = 0; i < dt2.Columns.Count; i++) r1[i] = r[i].ToString();
				dt1.Rows.Add(r1);
			}
			return dt1;
		}

		public bool upd_eve_tables(int tableid,int userid,string command)
		{
			string ngay = ngayhienhanh_server.Substring(0, 10),table="a_eve_tables";
			int icomputerid = iRownum,ins=0,upd=0,del=0;
			switch (command)
			{
				case "upd": upd = 1; break;
				case "del": del = 1; break;
				default: ins = 1; break;
			}
			sql="update "+table+" set ins=ins+"+ins+",upd=upd+"+upd+",del=del+"+del+" where tableid="+tableid+" and to_char(ngay,'dd/mm/yyyy')='"+ngay+"' and userid="+userid;
			con = new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(tableid,ngay,userid,computerid,ins,upd,del) values ";
					sql+="("+tableid+",to_date('"+ngay+"','dd/mm/yyyy'),"+userid+","+icomputerid+","+ins+","+upd+","+del+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch (OracleException ex)
			{
				upd_error(ex.Message, sComputer, table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
				
			}
			return true;
		}

		public bool upd_eve_upd_del(int tableid,int userid,string command,string noidung)
		{
			int icomputerid = iRownum;
			string table="a_eve_upd_del";
			sql="insert into "+table+"(tableid,userid,computerid,command,noidung) values ";
			sql+="("+tableid+","+userid+","+icomputerid+",'"+command+"',:noidung)";
			con = new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("noidung", OracleType.NVarChar,2000).Value = noidung;
				cmd.ExecuteNonQuery();
				cmd.Dispose();
			}
			catch (OracleException ex)
			{
				upd_error(ex.Message, sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();				
			}
			return true;
		}

		private int tableid()
		{
			ds = get_data("select max(id) as id from a_dmtables");
			if (ds.Tables[0].Rows[0]["id"].ToString()=="") return 1;
			else return int.Parse(ds.Tables[0].Rows[0]["id"].ToString()) + 1;
		}

		public int tableid(string mmyy,string tables)
		{
			int ret = 1;
			ds = get_data("select * from a_dmtables where tables='" + tables + "'");
			if (ds.Tables[0].Rows.Count > 0) ret=int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
			else
			{
				ret = tableid();
				string fie = "";
				for (int i = 0;i<get_data("select * from "+user+mmyy+"."+tables+" where rownum<0").Tables[0].Columns.Count; i++) fie += ds.Tables[0].Columns[i].ColumnName.ToString().Trim() + "^";
				execute_data("insert into a_dmtables(id,tables,fields) values (" + ret + ",'" + tables + "','"+fie.Substring(0,fie.Length-1)+"')");
			}
			return ret;
		}

		public string fields(string table,string dk)
		{
			string ret = "";
			DataTable dt = get_data("select * from " + table + " where "+dk).Tables[0];
			if (dt.Rows.Count>0) for (int i = 0; i < dt.Columns.Count; i++) ret += dt.Rows[0][i].ToString().Trim() + "^";
			return (ret != "") ? ret.Substring(0, ret.Length - 1) : ret;
		}

		public string file_modify(string tenfile)
		{
			string ret="";
			ret=System.IO.File.GetLastWriteTime(tenfile).ToString("dd/MM/yyyy HH:mm");
			System.IO.FileInfo fi=new System.IO.FileInfo(tenfile);
			ret+=" "+(fi.Length/1024).ToString();
			return ret;
		}

		public string f_modify(string tenfile)
		{
			return System.IO.File.GetLastWriteTime(tenfile).ToString("dd/MM/yyyy HH:mm");
		}

		public string f_size(string tenfile)
		{
			System.IO.FileInfo fi=new System.IO.FileInfo(tenfile);
			return (fi.Length/1024).ToString();
		}

		public bool bUpdate(string p_localhost,string p_server,string file)
		{
			bool modify=f_modify(file_exe(p_localhost,file))==f_modify(file_exe_update(p_server,file));
			bool size=f_size(file_exe(p_localhost,file))==f_size(file_exe_update(p_server,file));
			return modify && size;
		}

		public string file_exe_update(string path,string tenfilegoc)
		{
			string ret="";
			string [] files=System.IO.Directory.GetFiles(path);
			for(int i=0;i<files.GetLength(0);i++)
			{
				if (files[i].ToString().ToUpper().IndexOf(".EXE")!=-1 && tenfile(files[i].ToString())==tenfilegoc.ToLower())
				{
					ret=files[i].ToString();
					break;
				}
			}
			return ret;
		}

		public string path_medisofthis()
		{
			string path = System.IO.Directory.GetCurrentDirectory();
			string p_localhost = "";
			int j = 0,i=path.Length;
			for (; i >0; i--)
			{
				if (path.Substring(i-1, 1) == "\\") j++;
				if (j == 3) break;				
			}
			p_localhost = path.Substring(0,i-1);
			return p_localhost;
		}

		public void xcopy(string source,string dist)
		{
			string filerun=@path_medisofthis()+"\\version\\bin\\debug\\xcopy.exe";
			string arg=source+" "+dist+" /yes";
			run f=new run(filerun,arg,true);
			f.Launch();
		}

		public string tenfile_goc(string tenfile)
		{
			if (tenfile.Substring(0,1)=="\\")
			{
				string s=tenfile.Substring(tenfile.LastIndexOf("\\")+1);
				return s.Substring(0,s.IndexOf(".")).ToLower();
			}
			else
			{
				System.Reflection.Assembly asm=null;
				asm=System.Reflection.Assembly.LoadFrom(tenfile);
				return asm.GetName().Name.ToString().ToLower();
			}
		}

		public string tenfile(string tenfile)
		{
			string s=tenfile.Substring(tenfile.LastIndexOf("\\")+1);
			return s.Substring(0,s.LastIndexOf(".")).ToLower();
		}

		public string file_exe(string tenfilegoc)
		{
			string ret="";
			string [] files=System.IO.Directory.GetFiles(System.IO.Directory.GetCurrentDirectory());
			for(int i=0;i<files.GetLength(0);i++)
			{
				if (files[i].ToString().ToUpper().IndexOf(".EXE")!=-1 && tenfile_goc(files[i].ToString())==tenfilegoc.ToLower())
				{
					ret=files[i].ToString();
					break;
				}
			}
			return ret;
		}

		public string file_exe(string path,string tenfilegoc)
		{
			string ret="";
			string [] files=System.IO.Directory.GetFiles(path);
			for(int i=0;i<files.GetLength(0);i++)
			{
				if (files[i].ToString().ToUpper().IndexOf(".EXE")!=-1 && tenfile_goc(files[i].ToString())==tenfilegoc.ToLower())
				{
					ret=files[i].ToString();
					break;
				}
			}
			return ret;
		}

		public string file_exe_goc
		{
			get
			{
				string ret="";
				string [] files=System.IO.Directory.GetFiles(System.IO.Directory.GetCurrentDirectory());
				for(int i=0;i<files.GetLength(0);i++)
				{
					if (files[i].ToString().ToUpper().IndexOf(".EXE")!=-1)
					{
						ret=tenfile_goc(files[i].ToString());
						break;
					}
				}
				return ret;
			}
		}


		#region LICENSE
		private LinksLicense.LibLicense m_license = new LinksLicense.LibLicense();
		public bool upd_md_license(string v_computer_key, string v_license_key)
		{
			if(v_computer_key=="" || v_license_key=="") return false;
			sql="update m_license set license_key=:v_license_key where computer_key=:v_computer_key";
			con=new OracleConnection(sConn);
			cmd=new OracleCommand(sql,con);
			cmd.CommandType=CommandType.Text;

			cmd.Parameters.Add("v_computer_key",OracleType.NVarChar,255).Value=v_computer_key;
			cmd.Parameters.Add("v_license_key",OracleType.NVarChar,255).Value=v_license_key;

			try
			{
				con.Open();
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into m_license(computer_key,license_key) values(:v_computer_key,:v_license_key)";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;

					cmd.Parameters.Add("v_computer_key",OracleType.NVarChar,255).Value=v_computer_key;
					cmd.Parameters.Add("v_license_key",OracleType.NVarChar,255).Value=v_license_key;

					irec=cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,"m_license");
				return false;
			}
			finally
			{
				cmd.Dispose();
				con.Dispose();
			}		
			return true;
		}
		public bool is_licensed
		{
			get
			{
				bool ar=false;
				try
				{
					ar = f_get_md_license(m_license.f_generate_computer_key(),m_license.f_generate_license_key()).Tables[0].Rows.Count>0;
				}
				catch
				{
					ar=false;
				}
				return ar;
			}
		}
		public DataSet f_get_md_license(string v_computer_key, string v_license_key)
		{
			DataSet ads = null;
			try
			{
				string asql="", aexp="";
				asql="select * from m_license";

				if(v_computer_key!="") 
				{
					if(aexp.Length>0)
					{
						aexp+=" and";
					}
					aexp+=" computer_key=:v_computer_key";
				}
				if(v_license_key!="") 
				{
					if(aexp.Length>0)
					{
						aexp+=" and";
					}
					aexp+=" license_key=:v_license_key";
				}

				if(aexp.Length>0)
				{
					asql+=" where"+aexp;
				}
	
				con=new OracleConnection(sConn);
				con.Open();
				cmd=new OracleCommand(asql,con);
				cmd.CommandType=CommandType.Text;
				
				if(v_computer_key!="") 
				{
					cmd.Parameters.Add("v_computer_key",OracleType.NVarChar,255).Value=v_computer_key;
				}
				
				if(v_license_key!="") 
				{
					cmd.Parameters.Add("v_license_key",OracleType.NVarChar,255).Value=v_license_key;
				}

				dest=new OracleDataAdapter(cmd);
				ads=new DataSet();
				dest.Fill(ads);	
				cmd.Dispose();				
				con.Dispose();
			}
			catch(OracleException ex)
			{
				f_create_md_license();
				upd_error(ex.Message.ToString().Trim(),sComputer,"m_license");
			}
			return ads;
		}
		public void f_set_licensed(string v_password_)
		{
			try
			{
				if(v_password_==m_license.f_generate_password_key())
				{
					string acomputer_key="", alicence_key="";
					acomputer_key=m_license.f_generate_computer_key();
					alicence_key=m_license.f_generate_license_key();
					if(acomputer_key!="" && alicence_key!="")
					{
						upd_md_license(acomputer_key,alicence_key);
					}
				}
			}
			catch
			{
			}
		}
		public string s_computer_key
		{
			get
			{
				return m_license.f_generate_computer_key();
			}
		}
		public void f_create_md_license()
		{
			try
			{
				int n = get_data("select * from m_license where rownum<=1").Tables[0].Rows.Count;
			}
			catch
			{
				execute_data("create table m_license(computer_key nvarchar2(255), license_key nvarchar2(255), constraint pk_m_license primary key(computer_key))");
			}
		}
		#endregion

		//Lấy giá trị hiện tại của hệ thống ngày giờ
		private void get_current()
		{
			try
			{		
				//
				DataSet lds=new DataSet();
				if(File.Exists("..\\..\\..\\xml\\date_format.xml")==false)
				{
					DataTable ldt=new DataTable(); 
					ldt.TableName="t_date";
					ldt.Columns.Add("sShortDate");
					ldt.Columns.Add("sLongDate");
					ldt.Columns.Add("sDecimal");
					ldt.Columns.Add("sThousand");
					ldt.Columns.Add("sNegativeSign");				
					ldt.Columns.Add("iLZero");
					ldt.Columns.Add("sTime");
					ldt.Columns.Add("sDate");
					ldt.Columns.Add("sTimeFormat");
					ldt.Columns.Add("s1159");
					ldt.Columns.Add("s2359");
					//
					DataRow dr= ldt.NewRow();
					dr[0]=" ";
					dr[1]=" ";
					dr[2]=" ";
					dr[3]=" ";
					dr[4]=" ";
					dr[5]=" ";
					dr[6]=" ";
					dr[7]=" ";
					dr[8]=" ";
					dr[9]=" ";
					dr[10]=" ";
					ldt.Rows.Add(dr);
					ldt.AcceptChanges();
					//
					lds.Tables.Add(ldt);
					lds.AcceptChanges();				
					lds.WriteXml("..\\..\\..\\xml\\date_format.xml");
					lds.Dispose();
				}
				lds.ReadXml("..\\..\\..\\xml\\date_format.xml");
				lds.Tables[0].Clear();
				//
				string path = "Control Panel\\International";
				RegistryKey k = Registry.CurrentUser;//chỉ ảnh hưởng user hiện tại
				k = k.OpenSubKey(path, true);
				DataRow r = lds.Tables[0].NewRow();
				
				r["sShortDate"]=k.GetValue("sShortDate").ToString();//ngày kiểu shortdate
				r["sLongDate"]=k.GetValue("sLongDate").ToString();//, "dddd, MMMM dd, yyyy");//ngày kiểu longdate
				r["sDecimal"]=k.GetValue("sDecimal").ToString();//, ".");//giá trị thập phân
				r["sThousand"]=k.GetValue("sThousand").ToString();//, ",");//dấu nhóm chữ số 1,000,000
				r["sNegativeSign"]=k.GetValue("sNegativeSign").ToString();//, "-");//ký hiệu âm
				r["iLZero"]=k.GetValue("iLZero").ToString();//, "0");// 1:có '0' đứng trước 0.7; 0 ngược lại

				r["sTime"]=k.GetValue("sTime").ToString();//, ":");//dấu cách giữ hh:mm:ss
				r["sDate"]=k.GetValue("sDate").ToString();//, "/");//dấu cách giữ MM/dd/yyyy
				r["sTimeFormat"]=k.GetValue("sTimeFormat").ToString();//, "hh:mm:ss tt");//định định dạng thời gian
				r["s1159"]=k.GetValue("s1159").ToString();//, "AM");//buổi sáng
				r["s2359"]=k.GetValue("s2359").ToString();//, "PM");//buổi chiều				
				
				lds.Tables[0].Rows.Add(r);
				lds.AcceptChanges();
				lds.WriteXml("..\\..\\..\\xml\\date_format.xml");								

				k.Flush();

				lds.Dispose();
			}
			catch
			{ }
		}

		//set hệ thống ngày giờ theo quy định của chương trình
		public void setStandar()
		{
			get_current();
			try
			{
				string path = "Control Panel\\International";
				RegistryKey k = Registry.CurrentUser;//chỉ ảnh hưởng user hiện tại
				k = k.OpenSubKey(path, true);
				k.SetValue("sShortDate", "MM/dd/yyyy");//ngày kiểu shortdate
				k.SetValue("sLongDate", "dddd, MMMM dd, yyyy");//ngày kiểu longdate
				k.SetValue("sDecimal", ".");//giá trị thập phân
				k.SetValue("sThousand", ",");//dấu nhóm chữ số 1,000,000
				k.SetValue("sNegativeSign", "-");//ký hiệu âm
				k.SetValue("iLZero", "0");// 1:có '0' đứng trước 0.7; 0 ngược lại

				k.SetValue("sTime", ":");//dấu cách giữ hh:mm:ss
				k.SetValue("sDate", "/");//dấu cách giữ MM/dd/yyyy
				k.SetValue("sTimeFormat", "hh:mm:ss tt");//định định dạng thời gian
				k.SetValue("s1159", "AM");//buổi sáng
				k.SetValue("s2359", "PM");//buổi chiều

				k.Flush();
			}
			catch
			{ }
		}

		//trả lại ngày giờ hệ thống của máy lúc đầu.
		public void set_current()
		{
			try
			{
				string path = "Control Panel\\International";
				RegistryKey k = Registry.CurrentUser;//chỉ ảnh hưởng user hiện tại
				k = k.OpenSubKey(path, true);
				//
				//
				DataSet lds=new DataSet();
				lds.ReadXml("..\\..\\..\\xml\\date_format.xml");
				foreach(DataRow r in lds.Tables[0].Rows)
				{
					//
					k.SetValue("sShortDate", (r["sShortDate"].ToString()!="")?r["sShortDate"].ToString():"MM/dd/yyyy");//ngày kiểu shortdate
					k.SetValue("sLongDate", (r["sLongDate"].ToString()!="")?r["sLongDate"].ToString():"dddd, MMMM dd, yyyy");//ngày kiểu longdate
					k.SetValue("sDecimal", (r["sDecimal"].ToString()!="")?r["sDecimal"].ToString():".");//giá trị thập phân
					k.SetValue("sThousand", (r["sThousand"].ToString()!="")?r["sThousand"].ToString():",");//dấu nhóm chữ số 1,000,000
					k.SetValue("sNegativeSign", (r["sNegativeSign"].ToString()!="")?r["sNegativeSign"].ToString():"-");//ký hiệu âm
					k.SetValue("iLZero",(r["iLZero"].ToString()!="")?r["iLZero"].ToString():"0");// 1:có '0' đứng trước 0.7; 0 ngược lại

					k.SetValue("sTime", (r["sTime"].ToString()!="")?r["sTime"].ToString():":");//dấu cách giữ hh:mm:ss
					k.SetValue("sDate",(r["sDate"].ToString()!="")?r["sDate"].ToString(): "/");//dấu cách giữ MM/dd/yyyy
					k.SetValue("sTimeFormat", (r["sTimeFormat"].ToString()!="")?r["sTimeFormat"].ToString():"hh:mm:ss tt");//định định dạng thời gian
					k.SetValue("s1159", (r["s1159"].ToString()!="")?r["s1159"].ToString():"AM");//buổi sáng
					k.SetValue("s2359", (r["s2359"].ToString()!="")?r["s2359"].ToString():"PM");//buổi chiều

					k.Flush();
					break;
				}
			}
			catch
			{ }
		}

		public int getRandom()
		{
			System.Threading.Thread.Sleep(10);
			Random r = new Random();
			return r.Next(999);
		}

		public string getyymmddhhmisslocalhost()
		{
			return DateTime.Now.Year.ToString().PadLeft(4,'0').Substring(2,2)+DateTime.Now.Month.ToString().PadLeft(2,'0')+DateTime.Now.Day.ToString().PadLeft(2,'0')+DateTime.Now.Hour.ToString().PadLeft(2,'0')+DateTime.Now.Minute.ToString().PadLeft(2,'0')+DateTime.Now.Second.ToString().PadLeft(2,'0');
		}

		public string getyymmddhhmiss()
		{
			return get_data("select to_char(sysdate,'yymmddhh24miss') from dual").Tables[0].Rows[0][0].ToString();
		}

		public long getidyymmddhhmiss_stt_computer
		{
			get
			{
				return long.Parse(getyymmddhhmiss()+getRandom().ToString().PadLeft(3,'0')+iRownum.ToString().PadLeft(3,'0'));
			}
		}

		public long getidyymmddhhmiss_stt_computer_localhost
		{
			get
			{
				return long.Parse(getyymmddhhmisslocalhost()+getRandom().ToString().PadLeft(3,'0')+iRownum.ToString().PadLeft(3,'0'));
			}
		}

		public decimal getidyymmddhhmiss_stt_computer_localhost_mabv
		{
			get
			{
				return decimal.Parse(getyymmddhhmisslocalhost()+getRandom().ToString().PadLeft(3,'0')+iRownum.ToString().PadLeft(3,'0')+Mabv_so.ToString().PadLeft(6,'0'));
			}
		}

		public string getyymmdd()
		{
			return get_data("select to_char(sysdate,'yymmdd') from dual").Tables[0].Rows[0][0].ToString();
		}

		public long getidyymmdd(int id)
		{
			return long.Parse(getyymmdd() + get_capid_may(id, sComputer).ToString().PadLeft(9, '0') + iRownum.ToString().PadLeft(3, '0'));
		}

		private long get_capid_may(int m_ma,string m_computer)
		{
			sql="update a_capid set id=id+1 where ma=:m_ma and computer=:m_computer";
			con=new OracleConnection(sConn);
			con.Open();
			cmd=new OracleCommand(sql,con);
			cmd.CommandType=CommandType.Text;
			cmd.Parameters.Add("m_ma",OracleType.Number).Value=m_ma;
			cmd.Parameters.Add("m_computer",OracleType.VarChar).Value=m_computer;
			int irec=cmd.ExecuteNonQuery();
			cmd.Dispose();
			if (irec==0)
			{
				sql="insert into a_capid(ma,ten,id,computer) values (:m_ma,:m_ten,1,:m_computer)";
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("m_ma",OracleType.Int16).Value=m_ma;
				cmd.Parameters.Add("m_ten",OracleType.VarChar).Value=m_computer;
				cmd.Parameters.Add("m_computer",OracleType.VarChar).Value=m_computer;
				cmd.ExecuteNonQuery();
				cmd.Dispose();
			}
			sql="select id from a_capid where ma="+m_ma+" and computer='"+m_computer+"'";
			cmd=new OracleCommand(sql,con);
			cmd.CommandType=CommandType.Text;
			dest=new OracleDataAdapter(cmd);
			ds=new DataSet();
			dest.Fill(ds);	
			cmd.Dispose();				
			con.Close();con.Dispose();
			return long.Parse(ds.Tables[0].Rows[0][0].ToString());
		}

		public string getPathTemp
		{
			get
			{
				return System.IO.Path.GetTempPath();
			}
		}

		public void delFileTemp()
		{
			string[] files = System.IO.Directory.GetFiles(getPathTemp);
			for (int i = 0; i < files.GetLength(0); i++)
			{
				if (files[i].ToString().ToLower().IndexOf(".rpt") != -1 || files[i].ToString().ToLower().IndexOf(".tmp") != -1)
				{
					try
					{
						System.IO.File.Delete(files[i].ToString());
					}
					catch { }
				}
			}
		}
		public bool bMahoamatkhau
		{
			get
			{
				return get_data("select ten from a_thongso where id=-13").Tables[0].Rows.Count>0;
			}
		}

		public String tkchophanbo() 
		{
			try
			{
				return get_data("select ten from a_thongso where id=200").Tables[0].Rows[0]["ten"].ToString().Trim();
			}
			catch{return "";}
		}


		public string encode(string s)
		{
			string s1="";
			char c;
			byte b;
			s=s.Trim();
			for(int i=0;i<s.Length;i++)
			{
				c=Convert.ToChar(s.Substring(i,1).ToUpper());
				b=(byte)(c);
				s1=s1+Convert.ToChar((b%2==0)?b+128:b+96);
			}
			return s1;
		}

		public string decode(string s)
		{
			string s1="";
			char c;
			byte b;
			s=s.Trim();
			for(int i=0;i<s.Length;i++)
			{
				c=Convert.ToChar(s.Substring(i,1));
				b=(byte)(c);
				s1=s1+Convert.ToChar((b%2==0)?b-128:b-96);
			}
			return s1;
		}

		public void upd_dmcomputer(string m_computer)
		{
			sql="update dmcomputer set computer=:m_computer where computer=:m_computer";
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("m_computer",OracleType.VarChar).Value=m_computer;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into dmcomputer(computer) values (:m_computer)";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("m_computer",OracleType.VarChar).Value=m_computer;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(OracleException ex)
			{
				upd_error(ex.Message,sComputer,"dmcomputer");
			}
			finally
			{
				con.Close();con.Dispose();
			}		
		}
	
		public long getCapid(int m_ma)
		{
			sql="update a_capid set id=id+1 where ma=:m_ma";
			con=new OracleConnection(sConn);
			con.Open();
			cmd=new OracleCommand(sql,con);
			cmd.CommandType=CommandType.Text;
			cmd.Parameters.Add("m_ma",OracleType.Number).Value=m_ma;
			int irec=cmd.ExecuteNonQuery();
			cmd.Dispose();
			if (irec==0)
			{
				sql="insert into a_capid(ma,ten,computer,id) values (:m_ma,:ten,:ten,1)";
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("m_ma",OracleType.Number).Value=m_ma;
				cmd.Parameters.Add("ten",OracleType.VarChar).Value=sComputer;
				cmd.Parameters.Add("ten",OracleType.VarChar).Value=sComputer;
				cmd.ExecuteNonQuery();
				cmd.Dispose();
			}
			sql="select id from a_capid where ma="+m_ma;
			cmd=new OracleCommand(sql,con);
			cmd.CommandType=CommandType.Text;
			dest=new OracleDataAdapter(cmd);
			ds=new DataSet();
			dest.Fill(ds);	
			cmd.Dispose();				
			con.Close();con.Dispose();
			return long.Parse(ds.Tables[0].Rows[0][0].ToString());
		}
		public long getIdphantich() 
		{
			return getCapid(0);
		}

		public long getIdnghiepvu() 
		{
			return getCapid(1);
		}

		public long getIddmtinhchat() 
		{
			return getCapid(3);
		}

		public long getIddmtcnkp() 
		{
			return getCapid(4);
		}

		public long getIddmng() 
		{
			return getCapid(5);
		}

		public long getIddmngoaite() 
		{
			return getCapid(6);
		}

		public long getIdtonghop() 
		{
			return getCapid(7);
		}

		public long getIddmdt() 
		{
			return getCapid(8);
		}

		public long getIddmnh() 
		{
			return getCapid(9);
		}

		public long getIddmtk() 
		{
			return getCapid(10);
		}

		public long getIddmchucnang() 
		{
			return getCapid(11);
		}

		public long getIddmlk() 
		{
			return getCapid(12);
		}

		public long getIddmnhom() 
		{
			return getCapid(13);
		}

		public long getIdbcnghang() 
		{
			return getCapid(14);
		}

		public long getIdbtdkp() 
		{
			return getCapid(15);
		}

		public long getIddmch() 
		{
			return getCapid(16);
		}

		public long getIddmloaibk() 
		{
			return getCapid(17);
		}

		public long getIddmloaidt() 
		{
			return getCapid(18);
		}

		public long getIddmchuong() 
		{
			return getCapid(19);
		}

		public long getIddmtctk() 
		{
			return getCapid(20);
		}

		public long getIddmloaikm() 
		{
			return getCapid(29);
		}

		public long getIddmkhoanmuc() 
		{
			return getCapid(30);
		}

		public long getIdhoatdong() 
		{
			return getCapid(31);
		}

		public long getIddmloaihd() 
		{
			return getCapid(32);
		}

		public long getIddmdvt() 
		{
			return getCapid(38);
		}

		public long getIddmnhomkho() 
		{
			return getCapid(39);
		}

		public long getIddmkho() 
		{
			return getCapid(40);
		}

		public long getIddmnhom1() 
		{
			return getCapid(41);
		}

		public long getIddmnhom2() 
		{
			return getCapid(42);
		}

		public long getIddmnhom3() 
		{
			return getCapid(43);
		}

		public long getIddmloai() 
		{
			return getCapid(44);
		}

		public long getIddmpt() 
		{
			return getCapid(45);
		}

		public long getIddmnhomptnx() 
		{
			return getCapid(46);
		}

		public long getIddmptnx() 
		{
			return getCapid(47);
		}

		public long getIddmloaivt() 
		{
			return getCapid(48);
		}

		public long getIddmvt() 
		{
			return getCapid(49);
		}

		public long getIddmloaipttt() 
		{
			return getCapid(50);
		}

		public long getIddmpttt() 
		{
			return getCapid(51);
		}

		public long getIddmnguon() 
		{
			return getCapid(52);
		}

		public long getIddmloaikmcp() 
		{
			return getCapid(53);
		}

		public long getIddmkmcp() 
		{
			return getCapid(54);
		}

		public long getIdhachtoan() 
		{
			return getidyymmdd(20);
		}

		public long getIdtheodoihd() 
		{
			return getidyymmdd(21);
		}

		public long getIddenghi() 
		{
			return getidyymmdd(22);
		}

		public long getIdct() 
		{
			return getidyymmdd(23);
		}

		public long getIdctct() 
		{
			return getidyymmdd(24);
		}

		public long getIdcongno() 
		{
			return getidyymmdd(25);
		}

		public long getIdso() 
		{
			return getidyymmdd(26);
		}

		public long getIdctgs() 
		{
			return getidyymmdd(27);
		}

		public long getIddutoanns() 
		{
			return getidyymmdd(28);
		}

		public long getIdnhapll() 
		{
			return getidyymmdd(33);
		}

		public long getIdnhapct() 
		{
			return getidyymmdd(34);
		}

		public long getIdkhuyenmai() 
		{
			return getidyymmdd(35);
		}

		public long getIdxuatll() 
		{
			return getidyymmdd(36);
		}

		public long getIdxuatct() 
		{
			return getidyymmdd(37);
		}

		public long getIdphanbo() 
		{
			return getidyymmdd(55);
		}

		public long getIddmmaubc() 
		{
			return getidyymmdd(56);
		}

		public long getIdmaubc() 
		{
			return getidyymmdd(57);
		}

		public long getIdcongthuc() 
		{
			return getidyymmdd(58);
		}

		public bool bYyyy(String yyyy) 
		{
			return get_data("select * from a_table where yyyy='"+yyyy+"'").Tables[0].Rows.Count>0;
		}

		public bool bMmyy(String mmyy) 
		{
			return get_data("select * from a_mmyy where mmyy='"+mmyy+"'").Tables[0].Rows.Count>0;
		}

		public void taoTable(string yyyy, int userid) 
		{
			if (!bYyyy(yyyy)) 
			{
				string sql = "", yy = yyyy.Substring(2);

				sql = "CREATE TABLE a_congno"+yy+ "(id number(20),idbc number(5) default 0,loaidt number(2),chuong number(2),lk number(3),nghiepvu number(2),madt number(7),noidung nvarchar2(254),stka number(7),khoanmuc number(7) default 0,khoanmuc2 number(7) default 0,khoanmuc3 number(7) default 0,khoanmuc4 number(7) default 0,hoatdong number(2) DEFAULT 0,";
				sql += "	  sdno01 number(19,4) DEFAULT 0,sdco01 number(19,4) DEFAULT 0,ngoaite number(7) DEFAULT 0,tygia number(19,4) DEFAULT 0,sdnont01 number(19,4) DEFAULT 0,sdcont01 number(19,4) DEFAULT 0,userid number(5) DEFAULT 0, ngayud date DEFAULT sysdate,";
				sql += "	  CONSTRAINT pk_a_congno"+ yy+ " PRIMARY KEY (id));\n";

				sql += "CREATE TABLE a_ct"+ yy+ "(id number(20),idbc number(5) default 0,mact varchar2(10),chuong number(2),chucnang number(2),hoatdong number(2) DEFAULT 0,lctug number(3),soctg varchar2(50),ngayg date,";
				sql += "	 ngaygs date,noidung nvarchar2(254),tknoa number(7) DEFAULT 0,tkcoa number(7) DEFAULT 0,loaidt number(2),madt number(7),stien number(19,4) DEFAULT 0,";
				sql += "	 nguyente number(19,4) DEFAULT 0,thanggs varchar2(2),nghiepvu number(2),loaibk number(3) DEFAULT 0,";
				sql += "	 tcnkp number(3) DEFAULT 0,lanin number(3) DEFAULT 0,hopdong number(20) DEFAULT 0,ctgs varchar2(20),iddongthoi number(20) default 0,userid number(5) DEFAULT 0,ngayud date DEFAULT sysdate,";
				sql += "	 CONSTRAINT pk_a_ct"+ yy+ " PRIMARY KEY (id));\n";

				sql += "CREATE TABLE a_ctbk"+ yy+ "(id number(20),loaihd number(2),mauso varchar2(20),kyhieu varchar2(20),sohd varchar2(20),ngayhd date,thuexuat number(7,2) DEFAULT 0,";
				sql += "	tienthue number(19,4) DEFAULT 0,CONSTRAINT pk_a_ctbk"	+ yy+ " PRIMARY KEY (id));\n";

				sql += "CREATE TABLE a_ctbkct"+ yy+ "(id number(20),stt number(2),loaihd number(2) DEFAULT 0,mauso varchar2(20),kyhieu varchar2(20),sohd varchar2(20),";
				sql += "	ngayhd date,ten nvarchar2(254),masothue varchar2(20),noidung nvarchar2(254),stien number(19,4) DEFAULT 0,thuexuat number(7,2) DEFAULT 0,tienthue number(19,4) DEFAULT 0,";
				sql += "	CONSTRAINT pk_a_ctbkct"	+ yy+ " PRIMARY KEY (id, stt));\n";

				sql += "CREATE TABLE a_ctct"+ yy+ "(id number(20),idct number(20),stt number(3),lk number(3),noidung nvarchar2(254),tknoa number(7) DEFAULT 0,tkcoa number(7) DEFAULT 0,";
				sql += "	kmno number(7) DEFAULT 0,kmco number(7) DEFAULT 0,kmno2 number(7) DEFAULT 0,kmco2 number(7) DEFAULT 0,kmno3 number(7) DEFAULT 0,kmco3 number(7) DEFAULT 0,kmno4 number(7) DEFAULT 0,kmco4 number(7) DEFAULT 0,mtmno number(5) DEFAULT 0,mtmco number(5) DEFAULT 0,stien number(19,4),ngoaite number(7) DEFAULT 0,tygia number(10,2) DEFAULT 0,nguyente number(19,4),";
				sql += "	tonghop number(1) DEFAULT 0,mapt number(5) DEFAULT 0,ctgs number(20) DEFAULT 0,capphat number(2) default 0,thangqt varchar2(2),CONSTRAINT pk_a_ctct"	+ yy+ " PRIMARY KEY (id));\n";

				sql += "CREATE TABLE a_ctgs"+ yy+ "(id number(20),idbc number(5) default 0,chuong number(2),lk number(3),ctgs varchar2(20),ngaygs date,noidung nvarchar2(254),stien number(19,4) DEFAULT 0,";
				sql += "	thanggs varchar2(2),lctug number(3),chucnang number(2) DEFAULT 0,userid number(5) DEFAULT 0,ngayud date DEFAULT sysdate,";
				sql += "	CONSTRAINT pk_a_ctgs"+ yy+ " PRIMARY KEY (id));\n";

				sql += "CREATE TABLE a_ctk"	+ yy+ "(id number(20),tendt nvarchar2(254),diachi nvarchar2(254),CONSTRAINT pk_a_ctk"	+ yy+ " PRIMARY KEY (id));\n";

				sql += "CREATE TABLE a_dutoanns"+ yy+ "(id number(20),chuong number(2) DEFAULT 0,muc number(7) DEFAULT 0,nhmuc number(5),lk number(3),stk number(7) DEFAULT 0,";
				sql += "	khoanmuc number(7) default 0,khoanmuc2 number(7) default 0,khoanmuc3 number(7) default 0,khoanmuc4 number(7) default 0,hoatdong number(2) DEFAULT 0,dgiao number(19,4) DEFAULT 0,ntruoc number(19,4) DEFAULT 0,bsung number(19,4) DEFAULT 0,";
				sql += "	q number(2) DEFAULT 0,loaikp varchar2(1),kp number(5) DEFAULT 0,soctg varchar2(20),ngayg date,tcnkp number(3) DEFAULT 0,thanggs varchar2(2),idct number(20) default 0,userid number(5) DEFAULT 0,ngayud date DEFAULT sysdate,";
				sql += "	CONSTRAINT pk_a_dutoanns"+ yy+ " PRIMARY KEY (id));\n";

				sql += "CREATE TABLE a_fb"+ yy+ "(idbc number(5) default 0,chuong number(2),lk number(3) DEFAULT 0,tkno number(7), tkco number(7),";
				sql += "	kmno number(7) DEFAULT 0,kmco number(7) DEFAULT 0,kmno2 number(7) DEFAULT 0,kmco2 number(7) DEFAULT 0,kmno3 number(7) DEFAULT 0,kmco3 number(7) DEFAULT 0,kmno4 number(7) DEFAULT 0,kmco4 number(7) DEFAULT 0,hoatdong number(2) DEFAULT 0,nghiepvu number(2) default 0,fs01 number(19,4) DEFAULT 0,fs02 number(19,4) DEFAULT 0,";
				sql += "	fs03 number(19,4) DEFAULT 0,fs04 number(19,4) DEFAULT 0,fs05 number(19,4) DEFAULT 0,fs06 number(19,4) DEFAULT 0,fs07 number(19,4) DEFAULT 0,";
				sql += "	fs08 number(19,4) DEFAULT 0,fs09 number(19,4) DEFAULT 0,fs10 number(19,4) DEFAULT 0,fs11 number(19,4) DEFAULT 0,fs12 number(19,4) DEFAULT 0,";
				sql += "	fs13 number(19,4) DEFAULT 0,CONSTRAINT pk_a_fb"+ yy+ " PRIMARY KEY (idbc,chuong,lk, tkno, tkco, kmno, kmco,kmno2, kmco2,kmno3, kmco3,kmno4, kmco4, hoatdong,nghiepvu));\n";

				sql += "CREATE TABLE a_sd"+ yy+ "(idbc number(5) default 0,chuong number(2),lk number(3) DEFAULT 0,stka number(7),khoanmuc number(7) default 0,khoanmuc2 number(7) default 0,khoanmuc3 number(7) default 0,khoanmuc4 number(7) default 0,";
				sql += "	mtmuc number(5),nghiepvu number(2),madt number(7),hoatdong number(2) DEFAULT 0,sdno01 number(19,4) DEFAULT 0,";
				sql += "	sdco01 number(19,4) DEFAULT 0,fsno01 number(19,4) DEFAULT 0,fsco01 number(19,4) DEFAULT 0,sdno02 number(19,4) DEFAULT 0,sdco02 number(19,4) DEFAULT 0,";
				sql += "	fsno02 number(19,4) DEFAULT 0,fsco02 number(19,4) DEFAULT 0,sdno03 number(19,4) DEFAULT 0,sdco03 number(19,4) DEFAULT 0,fsno03 number(19,4) DEFAULT 0,";
				sql += "	fsco03 number(19,4) DEFAULT 0,sdno04 number(19,4) DEFAULT 0,sdco04 number(19,4) DEFAULT 0,fsno04 number(19,4) DEFAULT 0,fsco04 number(19,4) DEFAULT 0,";
				sql += "	sdno05 number(19,4) DEFAULT 0,sdco05 number(19,4) DEFAULT 0,fsno05 number(19,4) DEFAULT 0,fsco05 number(19,4) DEFAULT 0,sdno06 number(19,4) DEFAULT 0,";
				sql += "	sdco06 number(19,4) DEFAULT 0,fsno06 number(19,4) DEFAULT 0,fsco06 number(19,4) DEFAULT 0,sdno07 number(19,4) DEFAULT 0,sdco07 number(19,4) DEFAULT 0,";
				sql += "	fsno07 number(19,4) DEFAULT 0,fsco07 number(19,4) DEFAULT 0,sdno08 number(19,4) DEFAULT 0,sdco08 number(19,4) DEFAULT 0,fsno08 number(19,4) DEFAULT 0,";
				sql += "	fsco08 number(19,4) DEFAULT 0,sdno09 number(19,4) DEFAULT 0,sdco09 number(19,4) DEFAULT 0,fsno09 number(19,4) DEFAULT 0,fsco09 number(19,4) DEFAULT 0,";
				sql += "	sdno10 number(19,4) DEFAULT 0,sdco10 number(19,4) DEFAULT 0,fsno10 number(19,4) DEFAULT 0,fsco10 number(19,4) DEFAULT 0,sdno11 number(19,4) DEFAULT 0,";
				sql += "	sdco11 number(19,4) DEFAULT 0,fsno11 number(19,4) DEFAULT 0,fsco11 number(19,4) DEFAULT 0,sdno12 number(19,4) DEFAULT 0,sdco12 number(19,4) DEFAULT 0,";
				sql += "	fsno12 number(19,4) DEFAULT 0,fsco12 number(19,4) DEFAULT 0,sdno13 number(19,4) DEFAULT 0,sdco13 number(19,4) DEFAULT 0,fsno13 number(19,4) DEFAULT 0,";
				sql += "	fsco13 number(19,4) DEFAULT 0,sdno14 number(19,4) DEFAULT 0,sdco14 number(19,4) DEFAULT 0,";
				sql += "	CONSTRAINT pk_a_sd"	+ yy+ " PRIMARY KEY (idbc,chuong,lk, stka, khoanmuc, khoanmuc2, khoanmuc3, khoanmuc4, mtmuc, nghiepvu, madt, hoatdong));\n";

				sql += "CREATE TABLE a_sdc"+ yy+ "(idbc number(5) default 0,chuong number(2),lk number(3) DEFAULT 0,stka number(7),khoanmuc number(7) default 0,khoanmuc2 number(7) default 0,khoanmuc3 number(7) default 0,khoanmuc4 number(7) default 0,";
				sql += "	mtmuc number(5),nghiepvu number(2),madt number(7),hoatdong number(2) DEFAULT 0,sdno01 number(19,4) DEFAULT 0,";
				sql += "	sdco01 number(19,4) DEFAULT 0,fsno01 number(19,4) DEFAULT 0,fsco01 number(19,4) DEFAULT 0,sdno02 number(19,4) DEFAULT 0,sdco02 number(19,4) DEFAULT 0,";
				sql += "	fsno02 number(19,4) DEFAULT 0,fsco02 number(19,4) DEFAULT 0,sdno03 number(19,4) DEFAULT 0,sdco03 number(19,4) DEFAULT 0,fsno03 number(19,4) DEFAULT 0,";
				sql += "	fsco03 number(19,4) DEFAULT 0,sdno04 number(19,4) DEFAULT 0,sdco04 number(19,4) DEFAULT 0,fsno04 number(19,4) DEFAULT 0,fsco04 number(19,4) DEFAULT 0,";
				sql += "	sdno05 number(19,4) DEFAULT 0,sdco05 number(19,4) DEFAULT 0,fsno05 number(19,4) DEFAULT 0,fsco05 number(19,4) DEFAULT 0,sdno06 number(19,4) DEFAULT 0,";
				sql += "	sdco06 number(19,4) DEFAULT 0,fsno06 number(19,4) DEFAULT 0,fsco06 number(19,4) DEFAULT 0,sdno07 number(19,4) DEFAULT 0,sdco07 number(19,4) DEFAULT 0,";
				sql += "	fsno07 number(19,4) DEFAULT 0,fsco07 number(19,4) DEFAULT 0,sdno08 number(19,4) DEFAULT 0,sdco08 number(19,4) DEFAULT 0,fsno08 number(19,4) DEFAULT 0,";
				sql += "	fsco08 number(19,4) DEFAULT 0,sdno09 number(19,4) DEFAULT 0,sdco09 number(19,4) DEFAULT 0,fsno09 number(19,4) DEFAULT 0,fsco09 number(19,4) DEFAULT 0,";
				sql += "	sdno10 number(19,4) DEFAULT 0,sdco10 number(19,4) DEFAULT 0,fsno10 number(19,4) DEFAULT 0,fsco10 number(19,4) DEFAULT 0,sdno11 number(19,4) DEFAULT 0,";
				sql += "	sdco11 number(19,4) DEFAULT 0,fsno11 number(19,4) DEFAULT 0,fsco11 number(19,4) DEFAULT 0,sdno12 number(19,4) DEFAULT 0,sdco12 number(19,4) DEFAULT 0,";
				sql += "	fsno12 number(19,4) DEFAULT 0,fsco12 number(19,4) DEFAULT 0,sdno13 number(19,4) DEFAULT 0,sdco13 number(19,4) DEFAULT 0,fsno13 number(19,4) DEFAULT 0,";
				sql += "	fsco13 number(19,4) DEFAULT 0,sdno14 number(19,4) DEFAULT 0,sdco14 number(19,4) DEFAULT 0,";
				sql += "	CONSTRAINT pk_a_sdc"+ yy+ " PRIMARY KEY (idbc,chuong,lk, stka, khoanmuc,khoanmuc2, khoanmuc3, khoanmuc4, mtmuc, nghiepvu, madt, hoatdong));\n";

				sql += "CREATE TABLE a_so"+ yy+ "(id number(20),idbc number(5) default 0,chuong number(2),lk number(3),stka number(7),khoanmuc number(7) default 0,khoanmuc2 number(7) default 0,khoanmuc3 number(7) default 0,khoanmuc4 number(7) default 0,mtmuc number(5),nghiepvu number(2),";
				sql += "	hoatdong number(2) DEFAULT 0,sdno01 number(19,4) DEFAULT 0,sdco01 number(19,4) DEFAULT 0,ngoaite number(7) DEFAULT 0,tygia number(19,4) DEFAULT 0,";
				sql += "	sdnont01 number(19,4) DEFAULT 0,sdcont01 number(19,4) DEFAULT 0,userid number(5) DEFAULT 0,ngayud date DEFAULT sysdate,";
				sql += "	CONSTRAINT pk_a_so"	+ yy+ " PRIMARY KEY (id));\n";

				sql += "CREATE TABLE a_soc"	+ yy+ "(id number(20),idbc number(5) default 0,chuong number(2),lk number(3),stka number(7),khoanmuc number(7) default 0,khoanmuc2 number(7) default 0,khoanmuc3 number(7) default 0,khoanmuc4 number(7) default 0,mtmuc number(5),nghiepvu number(2),";
				sql += "	hoatdong number(2) DEFAULT 0,sdno01 number(19,4) DEFAULT 0,sdco01 number(19,4) DEFAULT 0,ngoaite number(7) DEFAULT 0,tygia number(19,4) DEFAULT 0,";
				sql += "	sdnont01 number(19,4) DEFAULT 0,sdcont01 number(19,4) DEFAULT 0,userid number(5) DEFAULT 0,ngayud date DEFAULT sysdate,";
				sql += "	CONSTRAINT pk_a_soc"+ yy+ " PRIMARY KEY (id));\n";
                /*
				sql += "CREATE TABLE a_nhapll"+ yy+ "(id number(20),mm varchar2(2),nhom number(2) DEFAULT 0,sophieu varchar2(20),ngaysp date,sohd varchar2(30),ngayhd date,nhomptnx number(5) DEFAULT 0,  maptnx number(5) DEFAULT 0,  makho number(5) DEFAULT 0,  manguon number(3) DEFAULT 0,  madv number(7) DEFAULT 0,  madvvat number(7) DEFAULT 0,  mapttt number(3) DEFAULT 0,ngaytt date,  mangoaite number(7) DEFAULT 0,  tygia number(10) DEFAULT 0,  hoten nvarchar2(254),  noidung nvarchar2(254),  no varchar2(254),  co varchar2(30),  mahopdong number(20) DEFAULT 0,  paid number(1) DEFAULT 0,  userid number(5) DEFAULT 0,  ngayud date DEFAULT sysdate,";
				sql += "	CONSTRAINT pk_a_nhapll"	+ yy+ " PRIMARY KEY (id));\n";

				sql += "CREATE TABLE a_nhapnk"+ yy+ "(  id number(20),  sotk varchar2(30),  ngaytk date,  soinvoice varchar2(30),  ngayinvoice date,  solc varchar2(30),  ngaylc date,  sobl varchar2(30),  ngaybl date,";
				sql += "	CONSTRAINT pk_a_nhapnk"	+ yy+ " PRIMARY KEY (id));\n";

				sql += "CREATE TABLE a_nhapct"+ yy+ "(id number(20) DEFAULT 0,idll number(20) DEFAULT 0,stt number(5) DEFAULT 0,mavt number(7) DEFAULT 0,tkdoiung number(7) DEFAULT 0, makmcp number(3) DEFAULT 0,  sl1 number(10,2) DEFAULT 0,  sl2 number(5) DEFAULT 0,  soluong number(10,2) DEFAULT 0,  giamuacu number(19,4) DEFAULT 0,  giabancu number(19,4) DEFAULT 0,  CONSTRAINT pk_a_nhapct"+ yy	+ " PRIMARY KEY (id));\n";

				sql += "CREATE TABLE a_theodoigia"+ yy+ "(  mm varchar2(2),  mavt number(7) DEFAULT 0,  ngay date,  dongia number(19,4) DEFAULT 0,  ngayud date DEFAULT sysdate,";
				sql += "	CONSTRAINT pk_a_theodoigia"	+ yy+ " PRIMARY KEY (mm, mavt, ngay));\n";

				sql += "CREATE TABLE a_theodoinhap"	+ yy+ "(  mm varchar2(2),  id number(20) DEFAULT 0,  manguon number(3),  madv number(7),  mavt number(7),  gia_goc number(19,4) DEFAULT 0,  st_goc number(19,4) DEFAULT 0,  tyle_vat number(7,2) DEFAULT 0,  st_vat number(19,4) DEFAULT 0,  gia_nt number(19,4) DEFAULT 0,  st_nt number(19,4) DEFAULT 0,  tyle_nk number(7,2) DEFAULT 0,  st_nk number(19,4) DEFAULT 0,  tyle_ck number(7,2) DEFAULT 0,  st_ck number(19,4) DEFAULT 0,  tyle_ggia number(7,2) DEFAULT 0,  st_ggia number(19,4) DEFAULT 0,  tyle_ttdb number(7,2) DEFAULT 0,  st_ttdb number(19,4) DEFAULT 0,  tyle_hh number(7,2) DEFAULT 0,  st_hh number(19,4) DEFAULT 0,  tyle_ban number(7,2) DEFAULT 0,  giaban number(19,4) DEFAULT 0,  st_ban number(19,4) DEFAULT 0,  dongia number(19,4) DEFAULT 0,  sotien number(19,4) DEFAULT 0,";
				sql += "	CONSTRAINT pk_a_theodoinhap"	+ yy+ " PRIMARY KEY (mm, id));\n";

				sql += "CREATE TABLE a_tonkhoct"+ yy+ "(  mm varchar2(2),  makho number(3),  stt number(20),  mavt number(7),  tondau number(12,2) DEFAULT 0,  slnhap number(12,2) DEFAULT 0,  slxuat number(12,2) DEFAULT 0,";
				sql += "  CONSTRAINT pk_a_tonkhoct"	+ yy+ " PRIMARY KEY (mm, makho, stt, mavt));\n";

				sql += "CREATE TABLE a_tonkhoth"+ yy+ "(  mm varchar2(2),  makho number(3),  manguon number(3),  mavt number(7),  tondau number(12,2) DEFAULT 0,  slnhap number(12,2) DEFAULT 0,  slxuat number(12,2) DEFAULT 0,";
				sql += "  CONSTRAINT pk_a_tonkhoth"	+ yy+ " PRIMARY KEY (mm, makho, manguon, mavt));\n";
                */
				sql += "CREATE TABLE a_hachtoan"+ yy+ "(id number(20),stk number(7),stkch number(7) DEFAULT 0,loai number(2) DEFAULT 0,\n";
				sql += "	 sudung number(1) DEFAULT 1,  userid number(5) DEFAULT 0,  ngayud date DEFAULT sysdate, CONSTRAINT pk_a_hachtoan"	+ yy+ " PRIMARY KEY (id));\n";

				sql +=" CREATE TABLE a_ctkc"+yy+" (id number(7,0),stt number (7,0),ketchuyen number(1,0),sobtoan varchar(10 ),\n";
				sql +="		tenbt nvarchar2(254 ) ,tinhchat number(1,0),tutk number(4,0),sangtk number (4,0),kmcpnguon varchar2(20),kmcpnguon2 varchar2(20),";
				sql +="		kmcpnguon3 varchar2(20 ),kmcpnguon4 varchar2(20 ),nhomkmcpn varchar2(20),dtthnguon varchar2(20),tukmcpn number(1,0),tukmcpn2 number(1,0),";
				sql +="		tukmcpn3 number(1,0),tukmcpn4 number(1,0),kmcpdich varchar2 (20 ),kmcpdich2 varchar2 (20),kmcpdich3 varchar2 (20),kmcpdich4 varchar2(20),";
				sql +="		tudtthn number(1,0),dtthdich varchar2(20 ),kysl number(5,0),lknguon varchar2(20),tulkn number(1,0) default 0,lkdich varchar2(20 ),userid number(5,0),";
				sql +="		ngayud date , CONSTRAINT pk_a_ctkc"	+ yy+ " PRIMARY KEY (id,stt) );\n";

				sql+="exit;";
				string tenfile="..\\..\\..\\xml\\tao.sql";
				if (File.Exists(tenfile)) File.Delete(tenfile);
				FileStream file = new FileStream(tenfile,FileMode.CreateNew,FileAccess.Write);
				StreamWriter sw = new StreamWriter(file);
				sw.Write(sql);
				sw.Close();
				string filerun=@"sqlplus.exe";
				string arg=user+"/"+user+"@"+service_name+" @"+tenfile;
				run f=new run(filerun,arg,true);
				f.Launch();
				if (File.Exists(tenfile)) File.Delete(tenfile);
				upd_table(yyyy, userid);
			}
		}

		public void modifyTable(string yyyy) 
		{
			if (bYyyy(yyyy)) 
			{
				string sql = "", yy = yyyy.Substring(2);


				sql ="ALTER TABLE A_FB"+yy+" DROP CONSTRAINT PK_A_FB"+yy+" CASCADE ;\n";
				sql +="ALTER TABLE A_sd"+yy+" DROP CONSTRAINT PK_A_sd"+yy+" CASCADE ;\n";
				sql +="ALTER TABLE A_sdc"+yy+" DROP CONSTRAINT PK_A_sdc"+yy+" CASCADE ;\n";
				sql += "alter table a_congno"+yy+ " add(khoanmuc2 number(7) default 0,khoanmuc3 number(7) default 0,khoanmuc4 number(7) default 0);\n";

				sql += "alter table a_ct"+yy+" add(iddongthoi number(20) default 0);\n";
				sql += "alter TABLE a_ctct"+ yy+ " add(kmno2 number(7) DEFAULT 0,kmco2 number(7) DEFAULT 0,kmno3 number(7) DEFAULT 0,kmco3 number(7) DEFAULT 0,kmno4 number(7) DEFAULT 0,kmco4 number(7) DEFAULT 0);\n";

				sql += "alter table a_dutoanns"+ yy+ " add(khoanmuc2 number(7) default 0,khoanmuc3 number(7) default 0,khoanmuc4 number(7) default 0);\n";
				sql += "alter table a_dutoanns"+yy+" add(thanggs varchar2(2));\n";
				sql += "alter table a_dutoanns"+yy+" add(idct number(20) default 0);\n";

				sql += "alter TABLE a_fb"+ yy+ " add(kmno2 number(7) DEFAULT 0,kmco2 number(7) DEFAULT 0,kmno3 number(7) DEFAULT 0,kmco3 number(7) DEFAULT 0,kmno4 number(7) DEFAULT 0,kmco4 number(7) DEFAULT 0);\n";

				sql += "alter TABLE a_sd"+ yy+ " add(khoanmuc2 number(7) default 0,khoanmuc3 number(7) default 0,khoanmuc4 number(7) default 0);\n";

				sql += "alter TABLE a_sdc"+ yy+ " add(khoanmuc2 number(7) default 0,khoanmuc3 number(7) default 0,khoanmuc4 number(7) default 0);\n";

				sql += "alter TABLE a_so"+ yy+ " add(khoanmuc2 number(7) default 0,khoanmuc3 number(7) default 0,khoanmuc4 number(7) default 0);\n";

				sql += "alter TABLE a_soc"	+ yy+ " add(khoanmuc2 number(7) default 0,khoanmuc3 number(7) default 0,khoanmuc4 number(7) default 0);\n";

				sql += "alter TABLE a_fbr add(kmno2 number(7) DEFAULT 0,kmco2 number(7) DEFAULT 0,kmno3 number(7) DEFAULT 0,kmco3 number(7) DEFAULT 0,kmno4 number(7) DEFAULT 0,kmco4 number(7) DEFAULT 0);\n";

				sql += "alter TABLE a_sdr add(khoanmuc2 number(7) default 0,khoanmuc3 number(7) default 0,khoanmuc4 number(7) default 0);\n";

				sql+="ALTER TABLE A_FB"+yy+" ADD (CONSTRAINT PK_A_FB"+yy+" PRIMARY KEY(IDBC,CHUONG,LK,TKNO,TKCO,KMNO,KMCO,KMNO2,KMCO2,KMNO3,KMCO3,KMNO4,KMCO4,HOATDONG,NGHIEPVU));\n";
				sql+="ALTER TABLE A_sd"+yy+" ADD (CONSTRAINT PK_A_sd"+yy+" PRIMARY KEY(idbc,chuong,lk, stka, khoanmuc, khoanmuc2, khoanmuc3, khoanmuc4, mtmuc, nghiepvu, madt, hoatdong));\n";
				sql+="ALTER TABLE A_sdc"+yy+" ADD (CONSTRAINT PK_A_sdc"+yy+" PRIMARY KEY(idbc,chuong,lk, stka, khoanmuc, khoanmuc2, khoanmuc3, khoanmuc4, mtmuc, nghiepvu, madt, hoatdong));\n";
				sql+="exit;";
				string tenfile="..\\..\\..\\xml\\tao.sql";
				if (File.Exists(tenfile)) File.Delete(tenfile);
				FileStream file = new FileStream(tenfile,FileMode.CreateNew,FileAccess.Write);
				StreamWriter sw = new StreamWriter(file);
				sw.Write(sql);
				sw.Close();
				string filerun=@"sqlplus.exe";
				string arg=user+"/"+user+"@"+service_name+" @"+tenfile;
				run f=new run(filerun,arg,true);
				f.Launch();
				if (File.Exists(tenfile)) File.Delete(tenfile);
			}
		}

		public bool upd_table(string d_yyyy,int d_userid)
		{
			sql="update a_table set userid="+d_userid+",computer='"+sComputer+"' where yyyy='"+d_yyyy+"'";
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into a_table(yyyy,userid,computer) values ('"+d_yyyy+"',"+d_userid+",'"+sComputer+"')";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,"a_table");
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool upd_bcnghang(long id,decimal stt,string maso,string ten,int baocao,string tenreport,int chucnang,
			string tkno,string tkco,int sudung,int idnh,int loai,string mact,int sophieu,int dutoanns,int userid)
		{
			string table="a_bcnghang";
			sql="update "+table+" set stt="+stt+",maso='"+maso+"',ten=:ten,baocao="+baocao+",tenreport='"+tenreport+"'";
			sql+=",chucnang="+chucnang+",tkno='"+tkno+"',tkco='"+tkco+"',sudung="+sudung+",";
			sql+="idnh="+idnh+",loai="+loai+",mact='"+mact+"',sophieu="+sophieu+",dutoanns="+dutoanns+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,stt,maso,ten,baocao,tenreport,chucnang,tkno,tkco,sudung,idnh,loai,mact,sophieu,dutoanns,userid) values ";
					sql+="("+id+","+stt+",'"+maso+"',:ten,'"+baocao+"','"+tenreport+"',"+chucnang+",'"+tkno+"','"+tkco+"',"+sudung+","+idnh+","+loai+",'"+mact+"',"+sophieu+","+dutoanns+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool upd_thongso(int id,string loai,string ten)
		{
			string table="a_thongso";
			sql="update "+table+" set ";
			if (loai!="") sql+="loai=:loai,";
			sql+="ten=:ten where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				if (loai!="") cmd.Parameters.Add("loai", OracleType.NVarChar,254).Value = loai;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,loai,ten) values ";
					sql+="("+id+",:loai,:ten)";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("loai", OracleType.NVarChar,254).Value = loai;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool upd_tonghop(int id,int stk,int tonghop,int sudung,int userid)
		{
			string table="a_tonghop";
			sql="update "+table+" set stk"+stk+",tonghop="+tonghop+",sudung="+sudung+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,stk,tonghop,sudung,userid) values ";
					sql+="("+id+","+stk+","+tonghop+","+sudung+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}
		public bool upd_phantich(int id,string mapt,string ten,int tinhchat,int sudung,int userid)
		{
			string table="a_phantich";
			sql="update "+table+" set mapt='"+mapt+"',ten=:ten,tinhchat="+tinhchat+",sudung="+sudung+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,mapt,ten,tinhchat,sudung,userid) values ";
					sql+="("+id+",'"+mapt+"',:ten,"+tinhchat+","+sudung+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool upd_mauketchuyen(int id,int stt,string tu,string den,string ten)
		{
			string table="a_mauketchuyen";
			sql="update "+table+" set stt="+stt+",tu='"+tu+"',den='"+den+"',ten=:ten";
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,stt,tu,den,ten) values ";
					sql+="("+id+","+stt+",'"+tu+"','"+den+"',:ten)";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}
		
		public bool upd_menuitems(int stt,int id,string ten,int loai)
		{
			string table="a_menuitems";
			sql="update "+table+" set stt="+stt+",ten=:ten,loai="+loai;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,stt,ten,loai) values ";
					sql+="("+id+","+stt+",:ten,"+loai+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}
		
		public bool upd_nghiepvu(int id,string ten,int sudung,int userid)
		{
			string table="a_nghiepvu";
			sql="update "+table+" set ten=:ten,sudung="+sudung+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,ten,sudung,userid) values ";
					sql+="("+id+",:ten,"+sudung+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool upd_hoatdong(int id,string ten,int sudung,int userid,string mhd_syt,string ma)
		{
			string table="a_hoatdong";
			sql="update "+table+" set ten=:ten,sudung="+sudung+",userid="+userid+",mhd_syt='"+mhd_syt+"',ma='"+ma+"'";
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,ten,sudung,userid,mhd_syt,ma) values ";
					sql+="("+id+",:ten,"+sudung+","+userid+",'"+mhd_syt+"','"+ma+"')";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool upd_dmtcnkp(int id,string ten,int sudung,int userid)
		{
			string table="a_dmtcnkp";
			sql="update "+table+" set ten=:ten,sudung="+sudung+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,ten,sudung,userid) values ";
					sql+="("+id+",:ten,"+sudung+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool upd_dmtctk(int id,string ten,string stk,int userid)
		{
			string table="a_dmtctk";
			sql="update "+table+" set ten=:ten,stk='"+stk+"',userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,ten,stk,userid) values ";
					sql+="("+id+",:ten,'"+stk+"',"+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}
		
		public bool upd_dmtinhchat(int id,int loai,string ten,string tknoa,string mtmno,
			string tkcoa,string mtmco,int userid)
		{
			string table="a_dmtinhchat";
			sql="update "+table+" set loai="+loai+",ten=:ten,tknoa='"+tknoa+"',mtmno='"+mtmno+"',tkcoa='"+tkcoa+"',";
			sql+="mtmco='"+mtmco+"',userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,loai,ten,tknoa,mtmno,tkcoa,mtmco,userid) values ";
					sql+="("+id+","+loai+",:ten,'"+tknoa+"','"+mtmno+"','"+tkcoa+"','"+mtmco+"',"+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}
		
		public bool upd_dmnhomtk(int id,string ten,int sudung,int userid)
		{
			string table="a_dmnhomtk";
			sql="update "+table+" set ten=:ten,sudung="+sudung+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,ten,sudung,userid) values ";
					sql+="("+id+",:ten,"+sudung+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}
		
		public bool upd_dmnhomkho(int id,int stt,string ten,int sudung,int userid)
		{
			string table="a_dmnhomkho";
			sql="update "+table+" set stt="+stt+",ten=:ten,sudung="+sudung+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,stt,ten,sudung,userid) values ";
					sql+="("+id+","+stt+",:ten,"+sudung+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}
		
		public bool upd_dmnhom(int id,string nhom,string tennhom,string muc,int sudung,int userid)
		{
			string table="a_dmnhom";
			sql="update "+table+" set nhom='"+nhom+"',tennhom=:tennhom,muc='"+muc+"',sudung="+sudung+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("tennhom", OracleType.NVarChar,254).Value = tennhom;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,nhom,tennhom,muc,sudung,userid) values ";
					sql+="("+id+",'"+nhom+"',:tennhom,'"+muc+"',"+sudung+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("tennhom", OracleType.NVarChar,254).Value = tennhom;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}
		
		public bool upd_dmng(long id,decimal stt,string mang,string ten,string chitiet,int loaikp,string thuocct,
			string ngaybd,string ngaykt,string coquanth,decimal tongkpdd,decimal sokptnlk,decimal sokpsdlk,
			decimal kpnamnay,int sudung,string mada,string mn_syt,string mact,string matieuct,int userid)
		{
			string table="a_dmng";
			sql="update "+table+" set stt="+stt+",mang='"+mang+"',ten=:ten,chitiet=:chitiet,loaikp="+loaikp+",thuocct=:thuocct,";
			if (ngaybd!="") sql+="ngaybd=to_date('"+ngaybd+"','dd/mm/yyyy'),";
			if (ngaykt!="") sql+="ngaykt=to_date('"+ngaykt+"','dd/mm/yyyy'),";
			sql+="coquanth=:coquanth,";
			sql+="tongkpdd="+tongkpdd+",sokptnlk="+sokptnlk+",kpnamnay="+kpnamnay+",sudung="+sudung;
			sql+=",mada='"+mada+"',mn_syt='"+mn_syt+"',mact='"+mact+"',matieuct='"+matieuct+"',userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				cmd.Parameters.Add("chitiet", OracleType.NVarChar,254).Value = chitiet;
				cmd.Parameters.Add("thuocct", OracleType.NVarChar,254).Value = thuocct;
				cmd.Parameters.Add("coquanth", OracleType.NVarChar,254).Value = coquanth;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,stt,mang,ten,chitiet,loaikp,thuocct,";
					if (ngaybd!="") sql+="ngaybd,";
					if (ngaykt!="") sql+="ngaykt,";
					sql+="coquanth,tongkpdd,sokptnlk,sokpsdlk,";
					sql+="kpnamnay,sudung,mada,mn_syt,mact,matieuct,userid) values ";
					sql+="("+id+","+stt+",'"+mang+"',:ten,:chitiet,"+loaikp+",:thuocct,";
					if (ngaybd!="") sql+="to_date('"+ngaybd+"','dd/mm/yyyy'),";
					if (ngaykt!="") sql+="to_date('"+ngaykt+"','dd/mm/yyyy'),";
					sql+=":coquanth,"+tongkpdd+","+sokptnlk+","+sokpsdlk;
					sql+=","+kpnamnay+","+sudung+",'"+mada+"','"+mn_syt+"','"+mact+"','"+matieuct+"',"+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.Parameters.Add("chitiet", OracleType.NVarChar,254).Value = chitiet;
					cmd.Parameters.Add("thuocct", OracleType.NVarChar,254).Value = thuocct;
					cmd.Parameters.Add("coquanth", OracleType.NVarChar,254).Value = coquanth;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool upd_dmngoaite(long id,string ma,string ten,string ngay,decimal tygia,int sudung,int userid)
		{
			string table="a_dmngoaite";
			sql="update "+table+" set ma='"+ma+"',ten=:ten,ngay=to_date('"+ngay+"','dd/mm/yyyy hh24:mi'),tygia="+tygia+",sudung="+sudung+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,ma,ten,ngay,tygia,sudung,userid) values ";
					sql+="("+id+",'"+ma+"',:ten,to_date('"+ngay+"','dd/mm/yyyy hh24:mi'),"+tygia+","+sudung+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}
		
		public bool upd_dmloaikp(string id,string ten,int sudung,int userid)
		{	
			string table="a_dmloaikp";
			sql="update "+table+" set ten=:ten,sudung="+sudung+",userid="+userid;
			sql+=" where id='"+id+"'";
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,ten,sudung,userid) values ";
					sql+="('"+id+"',:ten,"+sudung+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}
  
		public bool upd_dmloaipb(int id,int stt,string ten,int sudung,int userid)
		{
			string table="a_dmloaipb";
			sql="update "+table+" set stt="+stt+",ten=:ten,sudung="+sudung+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,stt,ten,sudung,userid) values ";
					sql+="("+id+","+stt+",:ten,"+sudung+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool upd_dmloaiphieu(int id,string ten,int sudung,int userid)
		{
			string table="a_dmloaiphieu";
			sql="update "+table+" set ten=:ten,sudung="+sudung+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,ten,sudung,userid) values ";
					sql+="("+id+",:ten,"+sudung+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}
		
		public bool upd_dmloaibk(int id,string ten,int loai,int sudung,int userid)
		{
			string table="a_dmloaibk";
			sql="update "+table+" set ten=:ten,loai="+loai+",sudung="+sudung+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,ten,loai,sudung,userid) values ";
					sql+="("+id+",:ten,"+loai+","+sudung+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}
		
		public bool upd_dmloaidt(int id,string ten,int sudung,int userid)
		{
			string table="a_dmloaidt";
			sql="update "+table+" set ten=:ten,sudung="+sudung+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,ten,sudung,userid) values ";
					sql+="("+id+",:ten,"+sudung+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}
		
		public bool upd_dmloaihd(int id,string ten,int loai,int sudung,int userid)
		{
			string table="a_dmloaihd";
			sql="update "+table+" set ten=:ten,loai="+loai+",sudung="+sudung+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,ten,loai,sudung,userid) values ";
					sql+="("+id+",:ten,"+loai+","+sudung+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}
		
		public bool upd_dmloaihdong(int id,int stt,string ten,int sudung,int userid)
		{
			string table="a_dmloaihdong";
			sql="update "+table+" set stt="+stt+",ten=:ten,sudung="+sudung+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,stt,ten,sudung,userid) values ";
					sql+="("+id+","+stt+",:ten,"+sudung+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}
		public bool upd_dmloaihtoan(int id,string ten,int sudung,int userid)
		{
			string table="a_dmloaihtoan";
			sql="update "+table+" set ten=:ten,sudung="+sudung+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,ten,sudung,userid) values ";
					sql+="("+id+",:ten,"+sudung+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool upd_dmloaikm(long id,decimal stt,string ten,int sudung,int userid)
		{
			string table="a_dmloaikm";
			sql="update "+table+" set stt="+stt+",ten=:ten,sudung="+sudung+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,stt,ten,sudung,userid) values ";
					sql+="("+id+","+stt+",:ten,"+sudung+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}
		
		public bool upd_dmlk(int id,decimal stt,string lk,string tlk,int sudung,int userid,string mn_syt)
		{
			string table="a_dmlk";
			sql="update "+table+" set stt="+stt+",lk='"+lk+"',tlk=:tlk,sudung="+sudung+",userid="+userid+",mn_syt='"+mn_syt+"'";
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("tlk", OracleType.NVarChar,254).Value = tlk;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,stt,lk,tlk,sudung,userid,mn_syt) values ";
					sql+="("+id+","+stt+",'"+lk+"',:tlk,"+sudung+","+userid+",'"+mn_syt+"')";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("tlk", OracleType.NVarChar,254).Value = tlk;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}
		
		public bool upd_dmdv(int id,int lk,int chuong,string mdv,string mdd,string ql,string tdv,string stk,
			string tkb,string tinh,string mans,string masothue,string  giamdoc,string  ktt,string ktth,
			string thuquy,string diachi,int userid)
		{
			string table="a_dmdv";
			sql="update "+table+" set lk="+lk+",chuong="+chuong+",mdv='"+mdv+"',mdd='"+mdd+"',ql='"+ql+"',tdv=:tdv,";
			sql+="stk='"+stk+"',tkb=:tkb,tinh=:tinh,mans='"+mans+"',masothue='"+masothue+"',giamdoc=:giamdoc,";
			sql+="ktt=:ktt,ktth=:ktth,thuquy=:thuquy,diachi=:diachi,userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("tdv", OracleType.NVarChar,254).Value = tdv;
				cmd.Parameters.Add("tkb", OracleType.NVarChar,254).Value = tkb;
				cmd.Parameters.Add("tinh", OracleType.NVarChar,254).Value = tinh;
				cmd.Parameters.Add("giamdoc", OracleType.NVarChar,254).Value = giamdoc;
				cmd.Parameters.Add("ktt", OracleType.NVarChar,254).Value = ktt;
				cmd.Parameters.Add("ktth", OracleType.NVarChar,254).Value = ktth;
				cmd.Parameters.Add("thuquy", OracleType.NVarChar,254).Value = thuquy;
				cmd.Parameters.Add("diachi", OracleType.NVarChar,254).Value = diachi;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,lk,chuong,mdv,mdd,ql,tdv,stk,tkb,tinh,mans,masothue,giamdoc,ktt,ktth,";
					sql+="thuquy,diachi,userid) values ";
					sql+="("+id+","+lk+","+chuong+",'"+mdv+"','"+mdd+"','"+ql+"',:tdv,'"+stk+"',:tkb,:tinh";
					sql+=",'"+mans+"','"+masothue+"',:giamdoc,:ktt,:ktth,:thuquy,:diachi,"+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("tdv", OracleType.NVarChar,254).Value = tdv;
					cmd.Parameters.Add("tkb", OracleType.NVarChar,254).Value = tkb;
					cmd.Parameters.Add("tinh", OracleType.NVarChar,254).Value = tinh;
					cmd.Parameters.Add("giamdoc", OracleType.NVarChar,254).Value = giamdoc;
					cmd.Parameters.Add("ktt", OracleType.NVarChar,254).Value = ktt;
					cmd.Parameters.Add("ktth", OracleType.NVarChar,254).Value = ktth;
					cmd.Parameters.Add("thuquy", OracleType.NVarChar,254).Value = thuquy;
					cmd.Parameters.Add("diachi", OracleType.NVarChar,254).Value = diachi;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool upd_dlogin(int id,string hoten,string userid,string password_,string right_,string chuong,
			string lk,string chucnang,string lctug,string nghiepvu,int admin)
		{
			string table="a_dlogin";
			sql="update "+table+" set hoten=:hoten,userid='"+userid+"',password_='"+password_+"',right_='"+right_+"'";
			sql+=",chuong='"+chuong+"',lk='"+lk+"',chucnang='"+chucnang+"',lctug='"+lctug+"',nghiepvu='"+nghiepvu+"',admin="+admin;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("hoten", OracleType.NVarChar,254).Value = hoten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,hoten,userid,password_,right_,chuong,lk,chucnang,lctug,nghiepvu,admin) values ";
					sql+="("+id+",:hoten,'"+userid+"','"+password_+"','"+right_+"','"+chuong+"','"+lk+"','"+chucnang+"','"+lctug+"','"+nghiepvu+"',"+admin+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("hoten", OracleType.NVarChar,254).Value = hoten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}
		
		public bool upd_dmcapphat(int id,string ten,int sudung,int userid)
		{
			string table="a_dmcapphat";
			sql="update "+table+" set ten=:ten,sudung="+sudung+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,ten,sudung,userid) values ";
					sql+="("+id+",:ten,"+sudung+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool upd_dmch(int id,string p,string n,string tn,string stk,string cc,string ttk,int c,int cd,int sp,
			int nhmuc,int sudung,int userid)
		{
			string table="a_dmch";
			sql="update "+table+" set p='"+p+"',n='"+n+"',tn='"+tn+"',stk='"+stk+"',cc='"+cc+"',ttk=:ttk,";
			sql+="c="+c+",cd="+cd+",sp="+sp+",nhmuc="+nhmuc+",sudung="+sudung+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ttk", OracleType.NVarChar,254).Value = ttk;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,p,n,tn,stk,cc,ttk,c,cd,sp,nhmuc,sudung,userid) values ";
					sql+="("+id+",'"+p+"','"+n+"','"+tn+"','"+stk+"','"+cc+"',:ttk,"+c+","+cd+","+sp+","+nhmuc+","+sudung+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ttk", OracleType.NVarChar,254).Value = ttk;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool upd_dmchucnang(int id,string ten,int sudung,int userid)
		{
			string table="a_dmchucnang";
			sql="update "+table+" set ten=:ten,sudung="+sudung+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,ten,sudung,userid) values ";
					sql+="("+id+",:ten,"+sudung+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}
		
		public bool upd_dmchuong(int id,string ma,string ten,int sudung,int userid)
		{
			string table="a_dmchuong";
			sql="update "+table+" set ma='"+ma+"',ten=:ten,sudung="+sudung+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,ma,ten,sudung,userid) values ";
					sql+="("+id+",'"+ma+"',:ten,"+sudung+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool upd_btdkp(long id,decimal stt,string makp,string tenkp,int sudung,int userid)
		{
			string table="a_btdkp";
			sql="update "+table+" set stt="+stt+",makp='"+makp+"',tenkp=:tenkp,sudung="+sudung+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("tenkp", OracleType.NVarChar,254).Value = tenkp;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,stt,makp,tenkp,sudung,userid) values ";
					sql+="("+id+","+stt+",'"+makp+"',:tenkp,"+sudung+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("tenkp", OracleType.NVarChar,254).Value = tenkp;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool upd_capid(int ma,string ten,long id,int idcomputer,string computer)
		{
			string table="a_capid";
			sql="update "+table+" set ten=:ten,id="+id+",idcomputer="+idcomputer+",computer='"+computer+"'";
			sql+=" where ma="+ma;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(ma,ten,id,idcomputer,computer) values ";
					sql+="("+ma+",:ten,"+id+","+idcomputer+",'"+computer+"')";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool upd_dmloaikmcp(int id,int stt,int nhom,string ten,int sudung,int userid)
		{
			string table="a_dmloaikmcp";
			sql="update "+table+" set stt="+stt+",nhom="+nhom+",ten=:ten,sudung="+sudung+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,stt,nhom,ten,sudung,userid) values ";
					sql+="("+id+","+stt+","+nhom+",:ten,"+sudung+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool upd_dmloai(int id,int stt,int nhom,string ten,int sudung,int userid)
		{
			return true;
		}

		public bool upd_dmpt(int id,int stt,int nhom,string ten,int sudung,int userid)
		{
			return true;
		}
		
		public bool upd_dmnhomptnx(int id,int stt,string ten,int loai,int mapt,int ngoaite,int nhapkhau,
			int ttdb,int chiphi,int vat,int chietkhau,int giamgia,int hoahong,int von,int thuenguoc,
			string nongoaite,string congoaite,string nonhapkhau,string conhapkhau,string nottdb,string cottdb,
			string nochiphi,string cochiphi,string novat,string	covat,string nochietkhau,string cochietkhau,
			string nogiamgia,string cogiamgia,string nohoahong,string cohoahong,string novon,string covon,
			int sudung,int userid)
		{
			return true;
		}
		
		public bool upd_dmnhom1(int id,int stt,int nhom,int loai,string ten,int sudung,int userid)
		{
			return true;
		}

		public bool upd_dmvt(long id,int nhom,long stt,string ma,string ten,int donggoi,int dvt,decimal slquidoi,
			int loai,int nhom1,int nhom2,int nhom3,long madv,int stkkho,int stkdthu,int stkchiphi,decimal giamua,
			decimal giaban,int thanhpham,int sudung,int userid)
		{
			return true;
		}

		public bool upd_khuyenmai(long id,string tu,string den,int nhomptnx,long mavt,decimal soluong,long mavtkm,
			long slkm,int userid)
		{
			return true;
		}

		public bool upd_dmdt(long id,decimal stt,string tendt,int makp,int loaidt,string diachi,string dienthoai,
			string email,string fax,string masothue,string sotaikhoan,string nganhang,string tinhtp,string daidien,
			string dtnr,string dtdd,string socmnd,string capngay,string noicap,string mavt,int sudung,
			string medisoft,string madvqhns,long manx,int userid)
		{
			string table="a_dmdt";
			sql="update "+table+" set stt="+stt+",tendt=:tendt,makp="+makp+",loaidt="+loaidt+",diachi=:diachi,";
			sql+="dienthoai='"+dienthoai+"',email='"+email+"',fax='"+fax+"',masothue='"+masothue+"',sotaikhoan='"+sotaikhoan+"'";
			sql+=",nganhang=:nganhang,tinhtp=:tinhtp,daidien=:daidien,dtnr='"+dtnr+"',dtdd='"+dtdd+"',socmnd='"+socmnd+"',";
			if (capngay!="") sql+="capngay=to_date('"+capngay+"','dd/mm/yyyy'),";
			sql+="noicap=:noicap,mavt='"+mavt+"',sudung="+sudung+",medisoft='"+medisoft+"',madvqhns='"+madvqhns+"'";
			sql+=",userid="+userid+",manx="+manx;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("tendt", OracleType.NVarChar,254).Value = tendt;
				cmd.Parameters.Add("diachi", OracleType.NVarChar,254).Value = diachi;
				cmd.Parameters.Add("nganhang", OracleType.NVarChar,254).Value = nganhang;
				cmd.Parameters.Add("tinhtp", OracleType.NVarChar,254).Value = tinhtp;
				cmd.Parameters.Add("daidien", OracleType.NVarChar,254).Value = daidien;
				cmd.Parameters.Add("noicap", OracleType.NVarChar,254).Value = noicap;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,stt,tendt,makp,loaidt,diachi,dienthoai,email,fax,masothue,sotaikhoan,";
					sql+="nganhang,tinhtp,daidien,dtnr,dtdd,socmnd,";
					if (capngay!="") sql+="capngay,";
					sql+="noicap,mavt,sudung,medisoft,madvqhns,manx,userid) values ";
					sql+="("+id+","+stt+",:tendt,"+makp+","+loaidt+",:diachi,'"+dienthoai+"','"+email+"','"+fax+"',";
					sql+="'"+masothue+"','"+sotaikhoan+"',:nganhang,:tinhtp,:daidien,'"+dtnr+"','"+dtdd+"','"+socmnd+"',";
					if (capngay!="") sql+="to_date('"+capngay+"','dd/mm/yyyy'),";
					sql+=":noicap,'"+mavt+"',"+sudung+",'"+medisoft+"','"+madvqhns+"',"+manx+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("tendt", OracleType.NVarChar,254).Value = tendt;
					cmd.Parameters.Add("diachi", OracleType.NVarChar,254).Value = diachi;
					cmd.Parameters.Add("nganhang", OracleType.NVarChar,254).Value = nganhang;
					cmd.Parameters.Add("tinhtp", OracleType.NVarChar,254).Value = tinhtp;
					cmd.Parameters.Add("daidien", OracleType.NVarChar,254).Value = daidien;
					cmd.Parameters.Add("noicap", OracleType.NVarChar,254).Value = noicap;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool upd_dmkho(int id,int stt,int nhom,string ten,int sudung,int userid)
		{
			return true;
		}

		public bool upd_dmkhoanmuc(long id,decimal stt,int loaikm,string ma,string ten,int sudung,int userid)
		{
			string table="a_dmkhoanmuc";
			sql="update "+table+" set stt="+stt+",loaikm="+loaikm+",ma='"+ma+"',ten=:ten,sudung="+sudung+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,stt,loaikm,ma,ten,sudung,userid) values ";
					sql+="("+id+","+stt+","+loaikm+",'"+ma+"',:ten,"+sudung+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool upd_dmkmcp(int id,int stt,int loai,string ten,int sudung,int userid)
		{
			string table="a_dmkmcp";
			sql="update "+table+" set stt="+stt+",loai="+loai+",ten=:ten,sudung="+sudung+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,stt,loai,ten,sudung,userid) values ";
					sql+="("+id+","+stt+","+loai+",:ten,"+sudung+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}
		public bool upd_dmloaipttt(int id,int stt,int nhom,string ten,int sudung,int userid)
		{
			return true;
		}
													   
		public bool upd_dmloaivt(int id,int stt,int nhom,string ten,int sudung,int userid)
		{
			return true;
		}
		
		public bool upd_dmnguon(int id,int stt,int nhom,string ten,int sudung,int userid)
		{
			return true;
		}

		public bool upd_dmtk(long id,string stk,string ttk,int tknb,int sp,int congno,int tinhchat,
			int mlns,int ctmlns,string tonghop,int bcdtk,int kiemtrasd,int sudung,int loaikm,
			int loaikm2,int loaikm3,int loaikm4,int nhom,int nghiepvu,int loaikhoan,int hoatdong,int chuong,
			int nhombc,int khoanmuc,int khoanmuc2,int khoanmuc3,int khoanmuc4,int userid)
		{
			string table="a_dmtk";
			sql="update "+table+" set stk='"+stk+"',ttk=:ttk,tknb="+tknb+",sp="+sp;
			sql+=",congno="+congno+",tinhchat="+tinhchat+",mlns="+mlns+",ctmlns="+ctmlns+",tonghop='"+tonghop+"'";
			sql+=",bcdtk="+bcdtk+",kiemtrasd="+kiemtrasd+",sudung="+sudung+",loaikm="+loaikm;
			sql+=",loaikm2="+loaikm2+",loaikm3="+loaikm3+",loaikm4="+loaikm4;
			sql+=",nhom="+nhom+",nghiepvu="+nghiepvu+",loaikhoan="+loaikhoan+",hoatdong="+hoatdong;
			sql+=",chuong="+chuong+",nhombc="+nhombc+",khoanmuc="+khoanmuc+",khoanmuc2="+khoanmuc2;
			sql+=",khoanmuc3="+khoanmuc3+",khoanmuc4="+khoanmuc4+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ttk", OracleType.NVarChar,254).Value = ttk;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,stk,ttk,c,tknb,sp,congno,tinhchat,mlns,ctmlns,tonghop,bcdtk,";
					sql+="kiemtrasd,sudung,loaikm,loaikm2,loaikm3,loaikm4,nhom,nghiepvu,loaikhoan,hoatdong,chuong,nhombc,khoanmuc,khoanmuc2,khoanmuc3,khoanmuc4,userid) values ";
					sql+="("+id+",'"+stk+"',:ttk,1,"+tknb+","+sp+","+congno+","+tinhchat+","+mlns+","+ctmlns+",'"+tonghop+"',"+bcdtk;
					sql+=","+kiemtrasd+","+sudung+","+loaikm+","+loaikm2+","+loaikm3+","+loaikm4+","+nhom+","+nghiepvu+","+loaikhoan+","+hoatdong+","+chuong+","+nhombc+","+khoanmuc+","+khoanmuc2+","+khoanmuc3+","+khoanmuc4+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ttk", OracleType.NVarChar,254).Value = ttk;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}
		
		public bool upd_dmnh(int id,decimal stt,long stk,string account,string tennh,int sudung,int userid)
		{
			string table="a_dmnh";
			sql="update "+table+" set stt="+stt+",stk="+stk+",account='"+account+"',tennh=:tennh,sudung="+sudung+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("tennh", OracleType.NVarChar,254).Value = tennh;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,stt,stk,account,tennh,sudung,userid) values ";
					sql+="("+id+","+stt+","+stk+",'"+account+"',:tennh,"+sudung+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("tennh", OracleType.NVarChar,254).Value = tennh;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool upd_dmnhom2(int id,int stt,int nhom,int loai,string ten,int sudung,int userid)
		{
			return true;
		}
		public bool upd_dmnhom3(int id,int stt,int nhom,int loai,string ten,int sudung,int userid)
		{
			return true;
		}

		public bool upd_dmptnx(int id,int stt,int nhom,string ten,int sudung,int userid)
		{
			return true;
		}

		public bool upd_dmpttt(int id,int stt,string ten,decimal thoihan,int loai,int sudung,int userid)
		{
			return true;
		}
		public bool upd_dmtonkho(int makho,long mavt,decimal soluong,int userid)
		{
			return true;
		}
		
		public bool updDtsd(string madv,string mmyy,int userid)
		{
			string table="a_dtsd";madv=(madv=="")?"?":madv;
			sql="update "+table+" set madv='"+madv+"',userid="+userid;
			sql+=" where mmyy='"+mmyy+"'";
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(madv,mmyy,userid) values ";
					sql+="('"+madv+"','"+mmyy+"',"+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool bKhoaso(string mmyy) 
		{
			return get_data("select * from a_khoaso where mmyy='"+mmyy+"'").Tables[0].Rows.Count>0;
		}

		public bool updKhoaso(string mmyy,int userid)
		{
			string table="a_khoaso";
			sql="update "+table+" set userid="+userid+" where mmyy='"+mmyy+"'";
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(mmyy,computer,userid) values ";
					sql+="('"+mmyy+"','"+sComputer+"',"+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool updMmyy(string mmyy,int userid)
		{
			string table="a_mmyy";
			sql="update "+table+" set userid="+userid+" where mmyy='"+mmyy+"'";
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(mmyy,computer,userid) values ";
					sql+="('"+mmyy+"','"+sComputer+"',"+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}
		public bool upd_phanbochua(long id,long idct,int lctug,string soctg,string ngayg,long tkno,long tkco,
			string kho,string noidung,decimal soluong,decimal sotien,decimal stda,int loai,int sothang,decimal tyle,
			decimal stphanbo,long tkphanbo,long km,int mtm,int nghiepvu,string mmyy,int userid)
		{
			return true;
		}
		public bool upd_phanboct(string mainkey,long id,long idct,int lctug,string soctg,string ngayg,long tkno,
			long tkco,string kho,string noidung,decimal soluong,decimal sotien,decimal stda,int loai,int sothang,
			decimal tyle,decimal stphanbo,long tkphanbo,long km,int mtm,int nghiepvu,long idk,long idctk,
			string mmyy,int userid)
		{
			return true;
		}
		
		public bool upd_theodoihd(long id,string ngay,string soqd,string ngayqd,string sohd,string ngayhd,string noidung,long madt,
			decimal stien,long denghi,int loai,decimal laisuat,string mmyy,int userid)
		{
			string table=user+".a_theodoihd";
			sql="update "+table+" set ngay=to_date('"+ngay+"','dd/mm/yyyy'),soqd=:soqd,ngayqd=to_date('"+ngayqd+"','dd/mm/yyyy'),sohd=:sohd,ngayhd=to_date('"+ngayhd+"','dd/mm/yyyy'),";
			sql+="noidung=:noidung,madt="+madt+",stien="+stien+",denghi="+denghi+",mmyy=:mmyy,userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try 
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("soqd",OracleType.VarChar,20).Value=soqd;
				cmd.Parameters.Add("sohd",OracleType.VarChar,100).Value=sohd;
				cmd.Parameters.Add("noidung",OracleType.NVarChar,254).Value=noidung;
				cmd.Parameters.Add("mmyy",OracleType.VarChar,4).Value=mmyy;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="INSERT INTO "+table+" (id,ngay,soqd,ngayqd,sohd,ngayhd,noidung,madt,stien,stdatra,denghi,loai,laisuat,mmyy,userid)";
					sql+=" VALUES("+id+",to_date('"+ngay+"','dd/mm/yyyy'),:soqd,to_date('"+ngayqd+"','dd/mm/yyyy'),:sohd,to_date('"+ngayhd+"','dd/mm/yyyy'),:noidung,"+madt+","+stien+",0,"+denghi+",0,0,:mmyy,"+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("soqd",OracleType.VarChar,20).Value=soqd;
					cmd.Parameters.Add("sohd",OracleType.VarChar,100).Value=sohd;
					cmd.Parameters.Add("noidung",OracleType.NVarChar,254).Value=noidung;
					cmd.Parameters.Add("mmyy",OracleType.VarChar,4).Value=mmyy;
					irec=cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			} 
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool upd_theodoihdct(long id, decimal stt, string so,string ngay,string no,string co,decimal sotien,
			string ghichu,int userid)
		{
			string table=user+".a_theodoihdct";
			sql="update "+table+" set so=:so,ngay=to_date('"+ngay+"','dd/mm/yyyy'),no=:no,co=:co,sotien="+sotien;
			sql+=",ghichu=:ghichu,userid="+userid+" where id="+id+" and stt="+stt;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("so",OracleType.VarChar,50).Value=so;
				cmd.Parameters.Add("no",OracleType.VarChar,100).Value=no;
				cmd.Parameters.Add("co",OracleType.VarChar,20).Value=co;
				cmd.Parameters.Add("ghichu",OracleType.NVarChar,254).Value=ghichu;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,stt,so,ngay,no,co,sotien,ghichu,userid) ";
					sql+="values ("+id+","+stt+",:so,to_date('"+ngay+"','dd/mm/yyyy'),:no,:co,"+sotien+",:ghichu,"+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("so",OracleType.VarChar,50).Value=so;
					cmd.Parameters.Add("no",OracleType.VarChar,100).Value=no;
					cmd.Parameters.Add("co",OracleType.VarChar,20).Value=co;
					cmd.Parameters.Add("ghichu",OracleType.NVarChar,254).Value=ghichu;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(OracleException ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				cmd.Dispose();
				con.Close();
			}
			return true;
		}

		public bool upd_thanhtoanct(string d_mmyy,long d_id, decimal d_stt, string d_so,string d_ngay,string d_no,string d_co,decimal d_sotien,
			string d_ghichu,int d_userid)
		{
			string xxx=user+"d"+d_mmyy;
			sql="update "+xxx+".d_thanhtoanct set so=:d_so,ngay=to_date('"+d_ngay+"','dd/mm/yyyy'),no=:d_no,co=:d_co,sotien="+d_sotien;
			sql+=",ghichu=:d_ghichu,userid="+d_userid+" where id="+d_id+" and stt="+d_stt;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("d_so",OracleType.VarChar,50).Value=d_so;
				cmd.Parameters.Add("d_no",OracleType.VarChar,100).Value=d_no;
				cmd.Parameters.Add("d_co",OracleType.VarChar,20).Value=d_co;
				cmd.Parameters.Add("d_ghichu",OracleType.NVarChar,254).Value=d_ghichu;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+xxx+".d_thanhtoanct(id,stt,so,ngay,no,co,sotien,ghichu,userid) ";
					sql+="values ("+d_id+","+d_stt+",:d_so,to_date('"+d_ngay+"','dd/mm/yyyy'),:d_no,:d_co,"+d_sotien+",:d_ghichu,"+d_userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("d_so",OracleType.VarChar,50).Value=d_so;
					cmd.Parameters.Add("d_no",OracleType.VarChar,100).Value=d_no;
					cmd.Parameters.Add("d_co",OracleType.VarChar,20).Value=d_co;
					cmd.Parameters.Add("d_ghichu",OracleType.NVarChar,254).Value=d_ghichu;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(OracleException ex)
			{
				upd_error(ex.Message,sComputer,"d_thanhtoanct");
				return false;
			}
			finally
			{
				cmd.Dispose();
				con.Close();
			}
			return true;
		}

		public bool updSodu(string table,long idbc, long chuong, long lk, long stka,long khoanmuc,
			long khoanmuc2,long khoanmuc3,long khoanmuc4,
			long mtmuc, long nghiepvu,long madt, long hoatdong,string mmyy, decimal sdno, decimal sdco) 
		{
			table = user+"." + table + mmyy.Substring(2);
			string mm = Convert.ToString(int.Parse(mmyy.Substring(0, 2))-1).PadLeft(2,'0');
			/*
			long value=-1;
			foreach(DataRow r in get_data("select * from a_dmtk where id="+stka).Tables[0].Rows)
			{
				if (int.Parse(r["chuong"].ToString())==0) chuong=value;
				if (int.Parse(r["loaikhoan"].ToString())==0) lk=value;
				if (int.Parse(r["nghiepvu"].ToString())==0) nghiepvu=value;
				if (int.Parse(r["congno"].ToString())==0) madt=value;
				if (int.Parse(r["loaikm"].ToString())==0) khoanmuc=value;
				if (int.Parse(r["mlns"].ToString())==0) mtmuc=value;
				if (int.Parse(r["hoatdong"].ToString())==0) hoatdong=value;
			}*/			
			sql = "update " + table + " set sdno" + mm + "=sdno" + mm + "+"+sdno+",";
			sql +="sdco"	+ mm + "=sdco" + mm + " + "+sdco+" where idbc="+idbc+" and chuong="+chuong;
			sql +=" and lk="+lk+" and stka="+stka+" and khoanmuc="+khoanmuc;
			sql +=" and khoanmuc2="+khoanmuc2+" and khoanmuc3="+khoanmuc3+" and khoanmuc4="+khoanmuc4;
			sql +=" and mtmuc="+mtmuc;
			sql +=" and nghiepvu="+nghiepvu+" and madt="+madt+" and hoatdong="+hoatdong;			
			con=new OracleConnection(sConn);
			try 
			{			
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql = "INSERT INTO "+ table	+ " (idbc,chuong,lk,stka,khoanmuc,khoanmuc2,khoanmuc3,khoanmuc4,mtmuc,nghiepvu,madt,hoatdong,";
					sql += "sdno" + mm + ",sdco" + mm + ")";
					sql += " values ("+idbc+","+chuong+","+lk+","+stka+","+khoanmuc+","+khoanmuc2+","+khoanmuc3+","+khoanmuc4+","+mtmuc+","+nghiepvu+","+madt+","+hoatdong;
					sql+=","+sdno+","+sdco+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			} 
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool updSodufs(string table,long idbc, long chuong, long lk, long stka,long khoanmuc,
			long khoanmuc2,long khoanmuc3,long khoanmuc4,long mtmuc, long nghiepvu,
			long madt, long hoatdong,string mmyy, decimal fsno, decimal fsco) 
		{
			table = user+"." + table + mmyy.Substring(2);
			string mm = mmyy.Substring(0, 2);
			/*
			long value=-1;
			foreach(DataRow r in get_data("select * from a_dmtk where id="+stka).Tables[0].Rows)
			{
				if (int.Parse(r["chuong"].ToString())==0) chuong=value;
				if (int.Parse(r["loaikhoan"].ToString())==0) lk=value;
				if (int.Parse(r["nghiepvu"].ToString())==0) nghiepvu=value;
				if (int.Parse(r["congno"].ToString())==0) madt=value;
				if (int.Parse(r["loaikm"].ToString())==0) khoanmuc=value;
				if (int.Parse(r["mlns"].ToString())==0) mtmuc=value;
				if (int.Parse(r["hoatdong"].ToString())==0) hoatdong=value;
			}*/			
			sql = "update " + table + " set fsno" + mm + "=fsno" + mm + "+"+fsno+",fsco";
			sql+= mm + "=fsco" + mm + "+"+fsco+" where idbc="+idbc+" and chuong="+chuong;
			sql+=" and lk="+lk+" and stka="+stka+" and khoanmuc="+khoanmuc;
			sql+=" and khoanmuc2="+khoanmuc2+" and khoanmuc3="+khoanmuc3+" and khoanmuc4="+khoanmuc4;
			sql+=" and mtmuc="+mtmuc;
			sql+=" and nghiepvu="+nghiepvu+" and madt="+madt+" and hoatdong="+hoatdong;
			con=new OracleConnection(sConn);
			try 
			{			
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql = "INSERT INTO "+ table	+ " (idbc,chuong,lk,stka,khoanmuc,khoanmuc2,khoanmuc3,khoanmuc4,mtmuc,nghiepvu,madt,hoatdong,";
					sql += "fsno" + mm + ",fsco" + mm + ")";
					sql += " values ("+idbc+","+chuong+","+lk+","+stka+","+khoanmuc+","+khoanmuc2+","+khoanmuc3+","+khoanmuc4+","+mtmuc+","+nghiepvu+","+madt+","+hoatdong;
					sql+=","+fsno+","+fsco+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			} 
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool updFb(long idbc,long chuong, long lk, long tkno, long tkco, long kmno,long kmco,
			long kmno2,long kmco2,long kmno3,long kmco3,long kmno4,long kmco4,long hoatdong, 
			long nghiepvu, string mmyy, decimal stien) 
		{
			string table = user+".a_fb" + mmyy.Substring(2), mm = mmyy.Substring(0,2);
			sql = "update " + table + " set fs" + mm + "=fs" + mm+ "+"+stien+" where idbc="+idbc+" and chuong="+chuong;
			sql+= " and lk="+lk+" and tkno="+tkno+" and tkco="+tkco+" and kmno="+kmno+" and kmco="+kmco;
			sql+= " and kmno2="+kmno2+" and kmco2="+kmco2+" and kmno3="+kmno3+" and kmco3="+kmco3+" and kmno4="+kmno4+" and kmco4="+kmco4;
			sql+= " and hoatdong="+hoatdong+" and nghiepvu="+nghiepvu;
			con=new OracleConnection(sConn);
			try 
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql = "INSERT INTO " + table+ " (idbc,chuong,lk,tkno,tkco,kmno,kmco,kmno2,kmco2,kmno3,kmco3,kmno4,kmco4,hoatdong,nghiepvu,";
					sql += "fs" + mm + ")";
					sql += " values ("+idbc+","+chuong+","+lk+","+tkno+","+tkco+","+kmno+","+kmco+","+kmno2+","+kmco2+","+kmno3+","+kmco3+","+kmno4+","+kmco4+","+hoatdong+","+nghiepvu;
					sql+=","+stien+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					irec=cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			} 
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		private DataSet getSodu(string table, string mmyyt, string mmyy) 
		{
			int i_mmyy=0;
			i_mmyy=int.Parse(mmyy.Substring(0,2).ToString())-1;		
			string usr=user,y1 = mmyyt.Substring(2), y2 = mmyy.Substring(2), m1 = mmyyt.Substring(0, 2), m2 = i_mmyy.ToString();//mmyy.Substring(0, 2);			
			m1=Convert.ToString(int.Parse(mmyyt.Substring(0, 2))-1).PadLeft(2,'0');//;	
			if (i_mmyy <= 1)
			{
				if (table == "a_sd") 
				{
					sql = " select 0 as loai,a.idbc,a.chuong,a.lk,a.stka,a.khoanmuc,a.khoanmuc2,a.khoanmuc3,a.khoanmuc4,0 as mtmuc,a.nghiepvu,a.madt,a.hoatdong,b.tinhchat,";
					sql += " a.sdno01 as sdno1,a.sdco01 as sdco1,0 as fsno1,0 as fsco1,0 as sdno,0 as sdco";
					sql += " from "+usr+".a_congno" + y2	+ " a,"+usr+".a_dmtk b where a.stka=b.id ";
					sql += " union all ";
					sql += " select 0 as loai,a.idbc,a.chuong,a.lk,a.stka,a.khoanmuc,a.khoanmuc2,a.khoanmuc3,a.khoanmuc4,a.mtmuc,a.nghiepvu,0 as madt,a.hoatdong,b.tinhchat,";
					sql += " a.sdno01 as sdno1,a.sdco01 as sdco1,0 as fsno1,0 as fsco1,0 as sdno,0 as sdco";
					sql += " from "+usr+".a_so" + y2+ " a,"+usr+".a_dmtk b where a.stka=b.id ";
				} 
				else 
				{
					sql = " select 0 as loai,a.idbc,a.chuong,a.lk,a.stka,a.khoanmuc,a.khoanmuc2,a.khoanmuc3,a.khoanmuc4,a.mtmuc,a.nghiepvu,0 as madt,a.hoatdong,b.tinhchat,";
					sql += " a.sdno01 as sdno1,a.sdco01 as sdco1,0 as fsno1,0 as fsco1,0 as sdno,0 as sdco";
					sql += " from "+usr+".a_soc" + y2 + " a,"+usr+".a_dmtk b where a.stka=b.id ";
				}
			} 
			else 
			{
				sql = "select 1 as loai,a.idbc,a.chuong,a.lk,a.stka,a.khoanmuc,a.khoanmuc2,a.khoanmuc3,a.khoanmuc4,a.mtmuc,a.nghiepvu,a.madt,a.hoatdong,b.tinhchat,";
				if (y1.IndexOf(y2) != -1) 
				{
					sql += "a.sdno" + m1 + " as sdno1,a.sdco" + m1 + " as sdco1,";
					sql += "a.fsno" + m1 + " as fsno1,a.fsco" + m1 + " as fsco1,";
					sql += "0 as sdno,0 as sdco";
				} 
				else 
				{
					sql += "case when a.sdno13<>0 then a.sdno13 else a.sdno12 end as sdno1,";
					sql += "case when a.sdco13<>0 then a.sdco13 else a.sdco12 end as sdco1,";
					sql += "case when a.sdno13<>0 then a.fsno13 else a.fsno12 end as fsno1,";
					sql += "case when a.sdco13<>0 then a.fsco13 else a.fsco12 end as fsco1,";
					sql += "a.sdno14 as sdno,a.sdco14 as sdco";
				}
				sql += " from "+usr+"." + table + y1	+ " a,"+usr+".a_dmtk b where a.stka=b.id";
				//sql +=" and a.stka=12";
			}
			decimal sdno = 0, sdco = 0;		
			int tinhchat=0;
			DataTable tmp=get_data(sql).Tables[0];
			ds=new DataSet();
			ds=get_data("select 0 as id from dual");
			ds.Tables[0].Columns.Add("idbc",typeof(decimal));
			ds.Tables[0].Columns.Add("chuong",typeof(decimal));
			ds.Tables[0].Columns.Add("lk",typeof(decimal));
			ds.Tables[0].Columns.Add("stka",typeof(decimal));
			ds.Tables[0].Columns.Add("khoanmuc",typeof(decimal));
			ds.Tables[0].Columns.Add("khoanmuc2",typeof(decimal));
			ds.Tables[0].Columns.Add("khoanmuc3",typeof(decimal));
			ds.Tables[0].Columns.Add("khoanmuc4",typeof(decimal));
			ds.Tables[0].Columns.Add("mtmuc",typeof(decimal));
			ds.Tables[0].Columns.Add("nghiepvu",typeof(decimal));
			ds.Tables[0].Columns.Add("madt",typeof(decimal));
			ds.Tables[0].Columns.Add("hoatdong",typeof(decimal));
			ds.Tables[0].Columns.Add("sdno",typeof(decimal));
			ds.Tables[0].Columns.Add("sdco",typeof(decimal));
			ds.Clear();

			foreach(DataRow r in tmp.Rows)
			{
				sdno = decimal.Parse(r["sdno1"].ToString());
				sdco = decimal.Parse(r["sdco1"].ToString());
				tinhchat=Convert.ToInt32(r["tinhchat"].ToString());			
				if (int.Parse(r["loai"].ToString()) == 1) 
				{
					switch (tinhchat) 
					{

						case 1:// tkno
							sdno= decimal.Parse(r["sdno1"].ToString()) + decimal.Parse(r["fsno1"].ToString())- decimal.Parse(r["fsco1"].ToString());							
							sdco= 0;							
							break;
						case 2: // tkco
							sdno= 0;
							sdco= decimal.Parse(r["sdco1"].ToString()) + decimal.Parse(r["fsco1"].ToString())- decimal.Parse(r["fsno1"].ToString());
							break;
						default:
							sdno= (decimal.Parse(r["sdno1"].ToString()) + decimal.Parse(r["fsno1"].ToString()))- Math.Min(decimal.Parse(r["sdno1"].ToString())+ decimal.Parse(r["fsno1"].ToString()), decimal.Parse(r["sdco1"].ToString())	+ decimal.Parse(r["fsco1"].ToString()));
							sdco= (decimal.Parse(r["sdco1"].ToString()) + decimal.Parse(r["fsco1"].ToString()))- Math.Min(decimal.Parse(r["sdno1"].ToString())+ decimal.Parse(r["fsno1"].ToString()), decimal.Parse(r["sdco1"].ToString())	+ decimal.Parse(r["fsco1"].ToString()));
							break;
					}
				}
				upditems(ds,long.Parse(r["idbc"].ToString()),long.Parse(r["chuong"].ToString()),long.Parse(r["lk"].ToString()),long.Parse(r["stka"].ToString()),
					long.Parse(r["khoanmuc"].ToString()),long.Parse(r["khoanmuc2"].ToString()),long.Parse(r["khoanmuc3"].ToString()),long.Parse(r["khoanmuc4"].ToString()),long.Parse(r["mtmuc"].ToString()),long.Parse(r["nghiepvu"].ToString()),
					long.Parse(r["madt"].ToString()),long.Parse(r["hoatdong"].ToString()),sdno,sdco);
			}				
			return ds;
		}

		private void upditems(DataSet ds,long idbc,long chuong,long lk,long stka,long khoanmuc,long khoanmuc2,long khoanmuc3,long khoanmuc4,long mtmuc,long nghiepvu,long madt,
			long hoatdong,decimal sdno,decimal sdco)
		{
			DataRow r=ds.Tables[0].NewRow();
			r["id"]=0;
			r["idbc"]=idbc;
			r["chuong"]=chuong;
			r["lk"]=lk;
			r["stka"]=stka;
			r["khoanmuc"]=khoanmuc;
			r["khoanmuc2"]=khoanmuc2;
			r["khoanmuc3"]=khoanmuc3;
			r["khoanmuc4"]=khoanmuc4;
			r["mtmuc"]=mtmuc;
			r["nghiepvu"]=nghiepvu;
			r["madt"]=madt;
			r["hoatdong"]=hoatdong;
			r["sdno"]=sdno;
			r["sdco"]=sdco;
			ds.Tables[0].Rows.Add(r);
		}
		
		public void updSodu(string mmyyt, string mmyy, int userid, bool sodu) 
		{
			ds=new DataSet();
			ds= getSodu("a_sd", mmyyt, mmyy);			
			mmyy=(sodu)?mmyy:mmyyt;
			string mmyys=(sodu)?mmyy:Mmyy_sau(mmyy);
			sql = "update "+user+".a_sd" + mmyy.Substring(2) + " set sdno"	+ mmyy.Substring(0, 2) + "=0,sdco" + mmyy.Substring(0, 2)+ "=0";
			execute_data(sql);
			foreach (DataRow r in ds.Tables[0].Select("sdco<>0 or sdno<>0"))
			{
				updSodu("a_sd",long.Parse(r["idbc"].ToString()),long.Parse(r["chuong"].ToString()),long.Parse(r["lk"].ToString()),long.Parse(r["stka"].ToString()),
					long.Parse(r["khoanmuc"].ToString()),long.Parse(r["khoanmuc2"].ToString()),long.Parse(r["khoanmuc3"].ToString()),long.Parse(r["khoanmuc4"].ToString()),long.Parse(r["mtmuc"].ToString()),long.Parse(r["nghiepvu"].ToString()),
					long.Parse(r["madt"].ToString()),long.Parse(r["hoatdong"].ToString()),mmyys,decimal.Parse(r["sdno"].ToString()),
					decimal.Parse(r["sdco"].ToString()));
			}
			sql = "delete from "+user+".a_dtsd where substr(mmyy,3,2)||substr(mmyy,1,2) between '";
			sql+= mmyyt.Substring(2)+ mmyyt.Substring(0, 2)	+ "' and '"	+ mmyy.Substring(2) + mmyy.Substring(0, 2) + "'";
			execute_data(sql);
			if (userid != 0)
				updDtsd("?", (sodu) ? Mmyy_sau(mmyy) : mmyy, userid);
			else
				updDtsd("?", Mmyy_sau(mmyy), userid);
		}

		public void updSoduc(string mmyyt, string mmyy, int userid, bool sodu) 
		{
			ds=new DataSet();
			ds = getSodu("a_sdc", mmyyt, mmyy);
			sql = "update "+user+".a_sdc" + mmyy.Substring(2) + " set sdno"	+ mmyy.Substring(0, 2) + "=0,sdco" + mmyy.Substring(0, 2)+ "=0";
			execute_data(sql);
			foreach (DataRow r in ds.Tables[0].Rows) 
			{
				updSodu("a_sdc",long.Parse(r["idbc"].ToString()),long.Parse(r["chuong"].ToString()),long.Parse(r["lk"].ToString()),long.Parse(r["stka"].ToString()),
					long.Parse(r["khoanmuc"].ToString()),long.Parse(r["khoanmuc2"].ToString()),long.Parse(r["khoanmuc3"].ToString()),long.Parse(r["khoanmuc4"].ToString()),long.Parse(r["mtmuc"].ToString()),long.Parse(r["nghiepvu"].ToString()),
					long.Parse(r["madt"].ToString()),long.Parse(r["hoatdong"].ToString()), mmyy,decimal.Parse(r["sdno"].ToString()),
					decimal.Parse(r["sdco"].ToString()));
			}
			sql = "delete from "+user+".a_dtsd where substr(mmyy,3,2)||substr(mmyy,1,2) between '"+ mmyyt.Substring(2)+ mmyyt.Substring(0, 2)	+ "' and '"	+ mmyy.Substring(2) + mmyy.Substring(0, 2) + "'";
			execute_data(sql);
			if (userid != 0)
				updDtsd("", (sodu) ? Mmyy_sau(mmyy) : mmyy, userid);
			else
				updDtsd("", Mmyy_sau(mmyy), userid);
		}

		private DataSet getSodu(string table, string mmyyt) 
		{
			ds=new DataSet();
			ds=get_data("select 0 as id from dual");
			ds.Tables[0].Columns.Add("idbc",typeof(decimal));
			ds.Tables[0].Columns.Add("chuong",typeof(decimal));
			ds.Tables[0].Columns.Add("lk",typeof(decimal));
			ds.Tables[0].Columns.Add("stka",typeof(decimal));
			ds.Tables[0].Columns.Add("khoanmuc",typeof(decimal));
			ds.Tables[0].Columns.Add("khoanmuc2",typeof(decimal));
			ds.Tables[0].Columns.Add("khoanmuc3",typeof(decimal));
			ds.Tables[0].Columns.Add("khoanmuc4",typeof(decimal));
			ds.Tables[0].Columns.Add("mtmuc",typeof(decimal));
			ds.Tables[0].Columns.Add("nghiepvu",typeof(decimal));
			ds.Tables[0].Columns.Add("madt",typeof(decimal));
			ds.Tables[0].Columns.Add("hoatdong",typeof(decimal));
			ds.Tables[0].Columns.Add("sdno",typeof(decimal));
			ds.Tables[0].Columns.Add("sdco",typeof(decimal));
			ds.Clear();
			string y1 = mmyyt.Substring(2);
			if (bYyyy("20" + y1)) 
			{
				sql = "select a.idbc,a.chuong,a.lk,a.stka,a.khoanmuc,a.khoanmuc2,a.khoanmuc3,a.khoanmuc4,a.mtmuc,a.nghiepvu,a.madt,a.hoatdong,b.tinhchat,";
				sql += "case when a.sdno13<>0 then a.sdno13 else a.sdno12 end as sdno1,";
				sql += "case when a.sdco13<>0 then a.sdco13 else a.sdco12 end as sdco1,";
				sql += "case when a.sdno13<>0 then a.fsno13 else a.fsno12 end as fsno1,";
				sql += "case when a.sdco13<>0 then a.fsco13 else a.fsco12 end as fsco1,";
				sql += "a.sdno14 as sdno,a.sdco14 as sdco";
				sql += " from "+user+"." + table + y1	+ " a,"+user+".a_dmtk b where a.stka=b.id";
				decimal sdno = 0, sdco = 0;
				DataTable tmp=get_data(sql).Tables[0];
				ds=new DataSet();
				ds=get_data("select 0 as id from dual");
				ds.Tables[0].Columns.Add("idbc",typeof(decimal));
				ds.Tables[0].Columns.Add("chuong",typeof(decimal));
				ds.Tables[0].Columns.Add("lk",typeof(decimal));
				ds.Tables[0].Columns.Add("stka",typeof(decimal));
				ds.Tables[0].Columns.Add("khoanmuc",typeof(decimal));
				ds.Tables[0].Columns.Add("khoanmuc2",typeof(decimal));
				ds.Tables[0].Columns.Add("khoanmuc3",typeof(decimal));
				ds.Tables[0].Columns.Add("khoanmuc4",typeof(decimal));
				ds.Tables[0].Columns.Add("mtmuc",typeof(decimal));
				ds.Tables[0].Columns.Add("nghiepvu",typeof(decimal));
				ds.Tables[0].Columns.Add("madt",typeof(decimal));
				ds.Tables[0].Columns.Add("hoatdong",typeof(decimal));
				ds.Tables[0].Columns.Add("sdno",typeof(decimal));
				ds.Tables[0].Columns.Add("sdco",typeof(decimal));
				ds.Clear();
				foreach(DataRow r in tmp.Rows)
				{
					sdno = decimal.Parse(r["sdno1"].ToString());
					sdco = decimal.Parse(r["sdco1"].ToString());
					switch (int.Parse(r["tinhchat"].ToString())) 
					{
						case 1:// tkno
							sdno = decimal.Parse(r["sdno1"].ToString()) + decimal.Parse(r["fsno1"].ToString())	- decimal.Parse(r["fsco1"].ToString());
							sdco = 0;
							break;
						case 2: // tkco
							sdno = 0;
							sdco = decimal.Parse(r["sdco1"].ToString()) + decimal.Parse(r["fsco1"].ToString())	- decimal.Parse(r["fsno1"].ToString());
							break;
						default:
							sdno = (decimal.Parse(r["sdno1"].ToString()) + decimal.Parse(r["fsno1"].ToString()))- Math.Min(decimal.Parse(r["sdno1"].ToString())	+ decimal.Parse(r["fsno1"].ToString()), decimal.Parse(r["sdco1"].ToString())+ decimal.Parse(r["fsco1"].ToString()));
							sdco = (decimal.Parse(r["sdco1"].ToString()) + decimal.Parse(r["fsco1"].ToString()))- Math.Min(decimal.Parse(r["sdno1"].ToString())	+ decimal.Parse(r["fsno1"].ToString()), decimal.Parse(r["sdco1"].ToString())+ decimal.Parse(r["fsco1"].ToString()));
							break;
					}
					upditems(ds,long.Parse(r["idbc"].ToString()),long.Parse(r["chuong"].ToString()),long.Parse(r["lk"].ToString()),long.Parse(r["stka"].ToString()),
						long.Parse(r["khoanmuc"].ToString()),long.Parse(r["khoanmuc2"].ToString()),long.Parse(r["khoanmuc3"].ToString()),long.Parse(r["khoanmuc4"].ToString()),long.Parse(r["mtmuc"].ToString()),long.Parse(r["nghiepvu"].ToString()),
						long.Parse(r["madt"].ToString()),long.Parse(r["hoatdong"].ToString()),sdno,sdco);
				}
			}
			return ds;
		}

		public void updChuyenso(string mmyyt, string mmyy, int userid) 
		{
			ds=new DataSet();
			ds= getSodu("a_sd", mmyyt);
			string usr=user;
			execute_data("delete "+usr+".a_so" + mmyy.Substring(2));
			execute_data("delete "+usr+".a_congno" + mmyy.Substring(2));
			execute_data("update "+usr+".a_sd" + mmyy.Substring(2) + " set sdno"	+ mmyy.Substring(0, 2) + "=0,sdco" + mmyy.Substring(0, 2)+ "=0");
			long id = 0;
			updDtsd("", "01" + mmyy.Substring(2), userid);
			foreach (DataRow r in ds.Tables[0].Rows)
			{
				if (int.Parse(r["madt"].ToString()) != 0) 
				{
					id = getIdcongno();
					updCongno(mmyy,id,long.Parse(r["idbc"].ToString()),0,long.Parse(r["chuong"].ToString()),long.Parse(r["lk"].ToString()),
						long.Parse(r["nghiepvu"].ToString()),long.Parse(r["madt"].ToString()),"",long.Parse(r["stka"].ToString()),
						long.Parse(r["khoanmuc"].ToString()),long.Parse(r["khoanmuc2"].ToString()),long.Parse(r["khoanmuc3"].ToString()),long.Parse(r["khoanmuc4"].ToString()),long.Parse(r["hoatdong"].ToString()),decimal.Parse(r["sdno"].ToString()),
						decimal.Parse(r["sdco"].ToString()), 0, 1,0, 0, userid);
				} 
				else 
				{
					id = getIdso();
					updSo("a_so",mmyy, id,long.Parse(r["idbc"].ToString()),long.Parse(r["chuong"].ToString()),long.Parse(r["lk"].ToString()),
						long.Parse(r["stka"].ToString()),long.Parse(r["khoanmuc"].ToString()),long.Parse(r["khoanmuc2"].ToString()),long.Parse(r["khoanmuc3"].ToString()),long.Parse(r["khoanmuc4"].ToString()),long.Parse(r["mtmuc"].ToString()),
						long.Parse(r["nghiepvu"].ToString()),long.Parse(r["hoatdong"].ToString()),decimal.Parse(r["sdno"].ToString()),
						decimal.Parse(r["sdco"].ToString()), 0, 1, 0, 0, userid);
				}
			}
			updDtsd("", mmyy, userid);
		}

		private string getValue(string sql)
		{
			string ret="";
			foreach(DataRow r in get_data(sql).Tables[0].Rows) ret=r["stk"].ToString().Trim();
			return ret;
		}
		public bool bChophanbo(long tkno, long tkco) 
		{
			string stkcho = tkchophanbo().Trim() + ",";
			string stkno = getValue("select stk from "+user+".a_dmtk where id=" + tkno)+ ",";
			string stkco = getValue("select stk from "+user+".a_dmtk where id=" + tkco)+ ",";
			return stkcho.IndexOf(stkno) != -1 || stkcho.IndexOf(stkco) != -1;
		}

		public void updPhanbo(string table, string tt, long id, long idct,long lctug, string soctg, string ngayg, 
			long tkno, long tkco,string kho, string noidung, decimal soluong, decimal sotien,	long nghiepvu, 
			string mmyy, long userid) 
		{
			if (tt == delete)
				execute_data("delete from "+user+"." + table + " where id=" + id);
			else 
			{
				sql = "update "+user+"."+ table	+ " set idct="+idct+",lctug="+lctug+",soctg='"+soctg+"',";
				if (ngayg!="") sql+="ngayg=to_date('"+ngayg+"','dd/mm/yyyy'),";
				sql+="tkno="+tkno+",tkco="+tkco+",kho=:kho,noidung=:noidung,soluong="+soluong;
				sql+=",sotien="+sotien+",nghiepvu="+nghiepvu+",mmyy='"+mmyy+"',userid="+userid+" where id="+id;
				con=new OracleConnection(sConn);
				try 
				{
					con.Open();
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("kho", OracleType.NVarChar,254).Value = kho;
					cmd.Parameters.Add("noidung", OracleType.NVarChar,254).Value = noidung;
					int irec=cmd.ExecuteNonQuery();
					cmd.Dispose();
					if (irec==0)
					{
						sql = "insert into "+user+"."+ table+ "(id,idct,lctug,soctg,";
						if (ngayg!="") sql+="ngayg,";
						sql+="tkno,tkco,kho,noidung,soluong,";
						sql+="sotien,nghiepvu,mmyy,userid) values ";
						sql+="("+id+","+idct+","+lctug+",'"+soctg+"',";
						if (ngayg!="") sql+="to_date('"+ngayg+"','dd/mm/yyyy'),";
						sql+=tkno+","+tkco+",:kho,:noidung,"+soluong+","+sotien+","+nghiepvu+",'"+mmyy+"',"+userid+")";
						cmd=new OracleCommand(sql,con);
						cmd.CommandType=CommandType.Text;
						cmd.Parameters.Add("kho", OracleType.NVarChar,254).Value = kho;
						cmd.Parameters.Add("noidung", OracleType.NVarChar,254).Value = noidung;
						irec=cmd.ExecuteNonQuery();
						cmd.Dispose();
					}
				} 
				catch(Exception ex)
				{
					upd_error(ex.Message,sComputer,table);
				}
				finally
				{
					con.Close();con.Dispose();
				}
			}
		}

		public void updPhanbo(string table, string tt, long id, decimal stda,long loai, long sothang, decimal tyle, 
			decimal stphanbo,long tkphanbo, long km, long mtm) 
		{
			if (tt == delete)
				execute_data("update "+user+"."+table+" set stda=stda-"+stda+",stphanbo=stphanbo-"+stphanbo+" where id="+id);
			else 
			{
				sql = "update "+user+"." + table+ " set stda=stda+"+stda+",loai="+loai+",sothang="+sothang+",tyle="+tyle+",";
				sql += "stphanbo=stphanbo+"+stphanbo+",km="+km+",mtm="+mtm+" where id="+id;
				execute_data(sql);
			}
		}

		public void updSodu(string table,string tt,string mmyy,long idbc,long chuong,long hopdong, long lk, long nghiepvu, 
			long madt, long tknoa,long tkcoa, long kmno, long kmco,long kmno2, long kmco2,long kmno3, long kmco3,long kmno4, long kmco4,
			long mtmno, long mtmco,	long hoatdong, decimal stien) 
		{
			string mm = mmyy.Substring(0, 2),usr=user;
			long lkno,lkco,nghiepvuno,nghiepvuco,madtno,madtco,kmnoa,kmcoa,mtmnoa,mtmcoa,hoatdongno,hoatdongco,chuongno,chuongco,value=-1;
			long kmnoa2,kmcoa2,kmnoa3,kmcoa3,kmnoa4,kmcoa4;
			chuongno=chuongco=chuong;
			lkno=lkco=lk;
			nghiepvuno=nghiepvuco=nghiepvu;
			madtno=madtco=madt;
			kmnoa=kmno;	kmcoa=kmco;
			kmnoa2=kmno2;kmcoa2=kmco2;
			kmnoa3=kmno3;kmcoa3=kmco3;
			kmnoa4=kmno4;kmcoa4=kmco4;
			mtmnoa=mtmno;mtmcoa=mtmco;
			hoatdongno=hoatdongco=hoatdong;
			/*
			foreach(DataRow r in get_data("select * from a_dmtk where id="+tknoa).Tables[0].Rows)
			{
				if (int.Parse(r["chuong"].ToString())==0) chuongno=value;
				if (int.Parse(r["loaikhoan"].ToString())==0) lkno=value;
				if (int.Parse(r["nghiepvu"].ToString())==0) nghiepvuno=value;
				if (int.Parse(r["congno"].ToString())==0) madtno=value;
				if (int.Parse(r["loaikm"].ToString())==0) kmnoa=value;
				if (int.Parse(r["mlns"].ToString())==0) mtmnoa=value;
				if (int.Parse(r["hoatdong"].ToString())==0) hoatdongno=value;
			}			
			foreach(DataRow r in get_data("select * from a_dmtk where id="+tkcoa).Tables[0].Rows)
			{
				if (int.Parse(r["chuong"].ToString())==0) chuongco=value;
				if (int.Parse(r["loaikhoan"].ToString())==0) lkco=value;
				if (int.Parse(r["nghiepvu"].ToString())==0) nghiepvuco=value;
				if (int.Parse(r["congno"].ToString())==0) madtco=value;
				if (int.Parse(r["loaikm"].ToString())==0) kmcoa=value;
				if (int.Parse(r["mlns"].ToString())==0) mtmcoa=value;
				if (int.Parse(r["hoatdong"].ToString())==0) hoatdongco=value;
			}*/			
			if (tt == delete) 
			{
				if (tknoa != 0) 
				{
					sql = "update "+usr+"." + table + mmyy.Substring(2)	+ " set fsno" + mm + "=fsno" + mm + "-" + stien;
					sql += " where idbc="+idbc+" and chuong=" + chuongno + " and lk=" + lkno+ " and stka=" + tknoa ;
					sql += " and khoanmuc=" + kmnoa+" and khoanmuc2=" + kmnoa2+" and khoanmuc3=" + kmnoa3;
					sql += " and khoanmuc4=" + kmnoa4+" and mtmuc=" + mtmnoa;
					sql += " and nghiepvu=" + nghiepvuno + " and madt=" + madtno + " and hoatdong=" + hoatdongno;
					execute_data(sql);
				}
				if (tkcoa != 0) 
				{
					sql = "update "+usr+"." + table + mmyy.Substring(2)	+ " set fsco" + mm + "=fsco" + mm + "-" + stien;
					sql += " where idbc="+idbc+" and chuong=" + chuongco + " and lk=" + lkco	+ " and stka=" + tkcoa ;
					sql += " and khoanmuc=" + kmcoa+" and khoanmuc2=" + kmcoa2 +" and khoanmuc3=" + kmcoa3 + " and khoanmuc4=" + kmcoa4;
					sql += " and mtmuc=" + mtmcoa;
					sql += " and nghiepvu=" + nghiepvuco + " and madt=" + madtco + " and hoatdong=" + hoatdongco;
					execute_data(sql);
				}
				if (tknoa != 0 && tkcoa != 0 && table == "a_sd") 
				{
					sql = "update "+usr+".a_fb" + mmyy.Substring(2) + " set fs" + mm+ "=fs" + mm + "-" + stien;
					sql += " where idbc="+idbc+" and chuong=" + chuong + " and lk=" + lk	+ " and tkno=" + tknoa + " and tkco=" + tkcoa;
					sql += " and kmno=" + kmno + " and kmco=" + kmco;
					sql += " and kmno2=" + kmno2 + " and kmco2=" + kmco2;
					sql += " and kmno3=" + kmno3 + " and kmco3=" + kmco3;
					sql += " and kmno4=" + kmno4 + " and kmco4=" + kmco4;
					sql += " and hoatdong=" + hoatdong;
					execute_data(sql);
				}
				/*if (hopdong != 0 && table == "a_sd")
					execute_data("update "+usr+".a_theodoihd set stdatra=stdatra-"+ stien + " where id=" + hopdong);*/
			} 
			else if (tt == insert) 
			{
				if (tknoa != 0)
					updSodufs(table,idbc, chuongno, lkno, tknoa, kmnoa,kmnoa2,kmnoa3,kmnoa4, mtmnoa, nghiepvuno,	madtno, hoatdongno, mmyy, stien, 0);
				if (tkcoa != 0)
					updSodufs(table,idbc, chuongco, lkco, tkcoa, kmcoa,kmcoa2,kmcoa3,kmcoa4, mtmcoa, nghiepvuco,	madtco, hoatdongco, mmyy, 0, stien);
				if (tknoa != 0 && tkcoa != 0 && table == "a_sd")
					updFb(idbc,chuong, lk, tknoa, tkcoa, kmnoa, kmcoa, kmnoa2, kmcoa2, kmnoa3, kmcoa3, kmnoa4, kmcoa4, hoatdong, nghiepvu,	mmyy, stien);
				/*if (hopdong != 0 && table == "a_sd")
					execute_data("update "+usr+".a_theodoihd set stdatra=stdatra+"+ stien + " where id=" + hopdong);*/
			}
		}

		public void updSodudau(string table, string tt, string mmyy,long idbc, long chuong,long lk, long stka, long khoanmuc, 
			long khoanmuc2, long khoanmuc3, long khoanmuc4, 
			long mtmuc, long nghiepvu,long madt, long hoatdong, decimal sdno, decimal sdco) 
		{
			if (tt == delete) 
			{
				sql = "update "+user+"." + table + mmyy.Substring(2)+ " set sdno01=sdno01-" + sdno;
				sql += ",sdco01=sdco01-" + sdco;
				sql += " where idbc="+idbc+" and chuong=" + chuong + " and lk=" + lk + " and stka="+ stka ;
				sql += " and khoanmuc=" + khoanmuc+" and khoanmuc2=" + khoanmuc2+" and khoanmuc3=" + khoanmuc3+" and khoanmuc4=" + khoanmuc4;
				sql += " and mtmuc=" + mtmuc + " and nghiepvu=" + nghiepvu;
				sql += " and madt=" + madt;
				sql += " and hoatdong=" + hoatdong;
				execute_data(sql);
			} 
			else if (tt == insert) 
				updSodudau(table, mmyy,idbc, chuong, lk, stka, khoanmuc,khoanmuc2,khoanmuc3,khoanmuc4, mtmuc,nghiepvu, madt, hoatdong, sdno, sdco);
		}

		public bool updSodudau(string table, string mmyy,long idbc, long chuong, long lk,	long stka, 
			long khoanmuc,long khoanmuc2,long khoanmuc3,long khoanmuc4, long mtmuc,
			long nghiepvu, long madt,long hoatdong, decimal sdno, decimal sdco) 
		{
			table = user+"." + table + mmyy.Substring(2);
			sql = "update " + table	+ " set sdno01=sdno01+"+sdno+",sdco01=sdco01+"+sdco+" where idbc="+idbc+" and chuong="+chuong;
			sql += " and lk="+lk+" and stka="+stka+" and khoanmuc="+khoanmuc;
			sql += " and khoanmuc2="+khoanmuc2+" and khoanmuc3="+khoanmuc3+" and khoanmuc4="+khoanmuc4;
			sql += " and mtmuc="+mtmuc+" and nghiepvu="+nghiepvu;
			sql += " and madt="+madt;
			sql += " and hoatdong="+hoatdong;
			con=new OracleConnection(sConn);
			try 
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql = "INSERT INTO " + table+ " (idbc,chuong,lk,stka,khoanmuc,khoanmuc2,khoanmuc3,khoanmuc4,mtmuc,nghiepvu,";
					sql += "madt,";
					sql += "hoatdong,sdno01,sdco01)";
					sql += " values ("+idbc+","+chuong+","+lk+","+stka+","+khoanmuc+","+khoanmuc2+","+khoanmuc3+","+khoanmuc4+","+mtmuc+","+nghiepvu+","+madt;
					sql += ","+hoatdong+","+sdno+","+sdco+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					irec=cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			} 
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool updCongno(string mmyy,long id,long idbc,int loaidt,long chuong, long lk,long nghiepvu,long madt,
			string noidung,long stka, long khoanmuc,long khoanmuc2,long khoanmuc3,long khoanmuc4, long hoatdong,decimal sdno01,decimal sdco01,long ngoaite,
			decimal tygia,decimal sdnont01,decimal sdcont01,int userid)
		{
			string table = user+".a_congno" + mmyy.Substring(2);
			sql="update "+table+" set idbc="+idbc+",loaidt="+loaidt+",chuong="+chuong+",lk="+lk+",nghiepvu="+nghiepvu+",madt="+madt;
			sql+=",noidung=:noidung,stka="+stka+",khoanmuc="+khoanmuc+",khoanmuc2="+khoanmuc2+",khoanmuc3="+khoanmuc3+",khoanmuc4="+khoanmuc4+",hoatdong="+hoatdong+",sdno01="+sdno01;
			sql+=",sdco01="+sdco01+",ngoaite="+ngoaite+",tygia="+tygia+",sdnont01="+sdnont01+",sdcont01="+sdcont01;
			sql+=",userid="+userid+" where id="+id;
			con=new OracleConnection(sConn);
			try 
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("noidung", OracleType.NVarChar,254).Value = noidung;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="INSERT INTO "+table+" (id,idbc,loaidt,chuong,lk,nghiepvu,madt,noidung,stka,khoanmuc,khoanmuc2,khoanmuc3,khoanmuc4,hoatdong,";
					sql+="sdno01,sdco01,ngoaite,tygia,sdnont01,sdcont01,userid)";
					sql+=" VALUES("+id+","+idbc+","+loaidt+","+chuong+","+lk+","+nghiepvu+","+madt+",:noidung,"+stka+","+khoanmuc+","+khoanmuc2+","+khoanmuc3+","+khoanmuc4+","+hoatdong;
					sql+=","+sdno01+","+sdco01+","+ngoaite+","+tygia+","+sdnont01+","+sdcont01+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("noidung", OracleType.NVarChar,254).Value = noidung;
					irec=cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			} 
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			updSodudau("a_sd",insert,mmyy,idbc,chuong,lk,stka,khoanmuc,khoanmuc2,khoanmuc3,khoanmuc4,0,nghiepvu,madt,hoatdong,sdno01,sdco01);
			return true;
		}

		public bool updSo(string table,string mmyy,long id,long idbc,long chuong, long lk,long stka, long khoanmuc,
			long khoanmuc2,long khoanmuc3,long khoanmuc4,
			long mtmuc,long nghiepvu,long hoatdong,decimal sdno01,decimal sdco01,long ngoaite,
			decimal tygia,decimal sdnont01,decimal sdcont01,int userid)
		{
			string _table=table;
			table = user+"."+table + mmyy.Substring(2);
			sql="update "+table+" set idbc="+idbc+",chuong="+chuong+",lk="+lk+",stka="+stka+",khoanmuc="+khoanmuc;
			sql+=",khoanmuc2="+khoanmuc2+",khoanmuc3="+khoanmuc3+",khoanmuc4="+khoanmuc4;
			sql+=",mtmuc="+mtmuc+",nghiepvu="+nghiepvu;
			sql+=",hoatdong="+hoatdong+",sdno01="+sdno01+",sdco01="+sdco01+",ngoaite="+ngoaite;
			sql+=",tygia="+tygia+",sdnont01="+sdnont01+",sdcont01="+sdcont01+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try 
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="INSERT INTO "+table+" (id,idbc,chuong,lk,stka,khoanmuc,khoanmuc2,khoanmuc3,khoanmuc4,mtmuc,nghiepvu,hoatdong";
					sql+=",sdno01,sdco01,ngoaite,tygia,sdnont01,sdcont01,userid)";
					sql+=" VALUES("+id+","+idbc+","+chuong+","+lk+","+stka+","+khoanmuc+","+khoanmuc2+","+khoanmuc3+","+khoanmuc4+","+mtmuc+","+nghiepvu+","+hoatdong;
					sql+=","+sdno01+","+sdco01+","+ngoaite+","+tygia+","+sdnont01+","+sdcont01+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					irec=cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			} 
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			updSodudau((_table=="a_so")?"a_sd":"a_sdc",insert,mmyy,idbc,chuong,lk,stka,khoanmuc,khoanmuc2,khoanmuc3,khoanmuc4,mtmuc,nghiepvu,0,hoatdong,sdno01,sdco01);
			return true;
		}

		public bool updDutoanns(string mmyy,long id,int chuong,long muc,int nhmuc,int lk,long stk,long khoanmuc,
			long khoanmuc2,long khoanmuc3,long khoanmuc4,int hoatdong,decimal q,string loaikp,int kp,
			string soctg,string ngayg,int tcnkp,decimal dgiao,decimal ntruoc,decimal bsung,int userid,
			long idct)
		{
			string table = user+".a_dutoanns" + mmyy.Substring(2);
			sql="update "+table+" set thanggs='"+mmyy.Substring(0,2)+"',chuong="+chuong+",muc="+muc+",nhmuc="+nhmuc+",lk="+lk+",stk="+stk;
			sql+=",khoanmuc="+khoanmuc+",khoanmuc2="+khoanmuc2+",khoanmuc3="+khoanmuc3+",khoanmuc4="+khoanmuc4+",hoatdong="+hoatdong;
			sql+=",dgiao="+dgiao+",ntruoc="+ntruoc+",bsung="+bsung+",q="+q+",loaikp='"+loaikp+"',kp="+kp;
			sql+=",soctg='"+soctg+"',ngayg=to_date('"+ngayg+"','dd/mm/yyyy'),tcnkp="+tcnkp;
			sql+=",idct="+idct+",userid="+userid+" where id="+id;
			con=new OracleConnection(sConn);
			try 
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="INSERT INTO "+table+" (id,thanggs,chuong,muc,nhmuc,lk,stk,khoanmuc,khoanmuc2,khoanmuc3,khoanmuc4,hoatdong,";
					sql+="dgiao,ntruoc,bsung,q,loaikp,kp,soctg,ngayg,tcnkp,idct,userid)";
					sql+=" VALUES("+id+",'"+mmyy.Substring(0,2)+"',"+chuong+","+muc+","+nhmuc+","+lk+","+stk+","+khoanmuc+","+khoanmuc2+","+khoanmuc3+","+khoanmuc4+","+hoatdong;
					sql+=","+dgiao+","+ntruoc+","+bsung+","+q+",'"+loaikp+"',"+kp+",'"+soctg+"',to_date('"+ngayg+"','dd/mm/yyyy'),"+tcnkp+","+idct+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					irec=cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			} 
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public void KiemtraFb(string tu, string den, int userid) 
		{
			string mm1 = tu.Substring(0, 2), mm2 = den.Substring(0, 2), yy = tu.Substring(2), mm = "",mmyys = "",usr=user,mmyyt="";
			int m1 = int.Parse(mm1), m2 = int.Parse(mm2);
			for (int i = m1; i <= m2; i++) 
			{
				mm = i.ToString().PadLeft(2,'0');
				execute_data("update "+usr+".a_sd" + yy + " set fsno" + mm+ "=0,fsco" + mm + "=0");
				execute_data("update "+usr+".a_fb" + yy + " set fs" + mm + "=0");
				sql = "select a.idbc,a.chuong,a.madt,a.nghiepvu,a.hoatdong,b.lk,b.tknoa,b.tkcoa,b.kmno,b.kmco,b.kmno2,b.kmco2,b.kmno3,b.kmco3,b.kmno4,b.kmco4,b.mtmno,b.mtmco,b.stien,b.thangqt";
				sql += " from "+usr+".a_ct" + yy + " a,"+usr+".a_ctct" + yy+ " b where a.id=b.idct ";
				sql += " and a.thanggs='" + mm + "'";
				sql += " and b.tonghop=1";
				foreach(DataRow r in get_data(sql).Tables[0].Rows)
				{
					if (long.Parse(r["tknoa"].ToString()) != 0) 
					{
						updSodufs("a_sd",long.Parse(r["idbc"].ToString()), long.Parse(r["chuong"].ToString()), long.Parse(r["lk"].ToString()), long.Parse(r["tknoa"].ToString()), long.Parse(r["kmno"].ToString()),long.Parse(r["kmno2"].ToString()),long.Parse(r["kmno3"].ToString()),long.Parse(r["kmno4"].ToString()), long.Parse(r["mtmno"].ToString()), long.Parse(r["nghiepvu"].ToString()), long.Parse(r["madt"].ToString()), long.Parse(r["hoatdong"].ToString()), mm + yy, decimal.Parse(r["stien"].ToString()), 0);
						if (r["thangqt"].ToString() != "")
							updSodufs("a_sdc",long.Parse(r["idbc"].ToString()), long.Parse(r["chuong"].ToString()), long.Parse(r["lk"].ToString()), long.Parse(r["tknoa"].ToString()), long.Parse(r["kmno"].ToString()),long.Parse(r["kmno2"].ToString()),long.Parse(r["kmno3"].ToString()),long.Parse(r["kmno4"].ToString()), long.Parse(r["mtmno"].ToString()), long.Parse(r["nghiepvu"].ToString()), long.Parse(r["madt"].ToString()),long.Parse(r["hoatdong"].ToString()), r["thangqt"].ToString()	+ yy, decimal.Parse(r["stien"].ToString()), 0);
					}
					if (long.Parse(r["tkcoa"].ToString()) != 0) 
					{
						updSodufs("a_sd",long.Parse(r["idbc"].ToString()),long.Parse(r["chuong"].ToString()), long.Parse(r["lk"].ToString()), long.Parse(r["tkcoa"].ToString()), long.Parse(r["kmco"].ToString()),long.Parse(r["kmco2"].ToString()),long.Parse(r["kmco3"].ToString()),long.Parse(r["kmco4"].ToString()), long.Parse(r["mtmco"].ToString()), long.Parse(r["nghiepvu"].ToString()), long.Parse(r["madt"].ToString()), long.Parse(r["hoatdong"].ToString()), mm + yy, 0, decimal.Parse(r["stien"].ToString()));
						if (r["thangqt"].ToString() != "")
							updSodufs("a_sdc",long.Parse(r["idbc"].ToString()),long.Parse(r["chuong"].ToString()), long.Parse(r["lk"].ToString()), long.Parse(r["tkcoa"].ToString()), long.Parse(r["kmco"].ToString()),long.Parse(r["kmco2"].ToString()),long.Parse(r["kmco3"].ToString()),long.Parse(r["kmco4"].ToString()), long.Parse(r["mtmco"].ToString()), long.Parse(r["nghiepvu"].ToString()), long.Parse(r["madt"].ToString()),long.Parse(r["hoatdong"].ToString()), r["thangqt"].ToString()	+ yy, 0, decimal.Parse(r["stien"].ToString()));
					}
					if (long.Parse(r["tknoa"].ToString()) != 0 && long.Parse(r["tkcoa"].ToString()) != 0)
						updFb(long.Parse(r["idbc"].ToString()),long.Parse(r["chuong"].ToString()), long.Parse(r["lk"].ToString()), long.Parse(r["tknoa"].ToString()), long.Parse(r["tkcoa"].ToString()), long.Parse(r["kmno"].ToString()), long.Parse(r["kmco"].ToString()),long.Parse(r["kmno2"].ToString()), long.Parse(r["kmco2"].ToString()),long.Parse(r["kmno3"].ToString()), long.Parse(r["kmco3"].ToString()),long.Parse(r["kmno4"].ToString()), long.Parse(r["kmco4"].ToString()), long.Parse(r["hoatdong"].ToString()), long.Parse(r["nghiepvu"].ToString()),	mm + yy, decimal.Parse(r["stien"].ToString()));
				}
				mmyys = Mmyy_sau(mm + yy);mmyyt=Mmyy_truoc(mm+yy);
				if (int.Parse(yy) == int.Parse(mmyys.Substring(2))) 
				{
					execute_data("update "+usr+".a_sd" + yy + " set sdno"	+ mmyys.Substring(0, 2) + "=0,sdco"	+ mmyys.Substring(0, 2) + "=0");
					updSodu(mm + yy, mmyys, userid, false);
					execute_data("update "+usr+".a_sdc" + yy + " set sdno" + mmyys.Substring(0, 2) + "=0,sdco"+ mmyys.Substring(0, 2) + "=0");
					updSoduc(mm + yy, mmyys, userid, false);
				}
				else execute_data("delete from "+usr+".a_dtsd where mmyy='"+mm+yy+"'");
			} 
		}

		public string KiemtraFb(string tu, string den) 
		{
			string s = "", mm1 = tu.Substring(0, 2), mm2 = den.Substring(0, 2), yy = tu.Substring(2), mm = "";
			int m1 = int.Parse(mm1), m2 = int.Parse(mm2);
			sql="SELECT mmyy,userid FROM "+user+".a_khoaso where substr(mmyy,3,2)='"+yy+"'";
			ds=new DataSet();
			ds=get_data(sql);
			DataRow r;
			for (int i = m1; i <= m2; i++) 
			{
				mm = i.ToString().PadLeft(2,'0');
				r=getrowbyid(ds.Tables[0],"mmyy='"+mm+yy+"'");
				if (r!=null) s += mm + ",";
			}
			return s;
		}

		public bool updSodufs(string table,long idbc, long chuong, long lk, long stka,long khoanmuc,
			long khoanmuc2,long khoanmuc3,long khoanmuc4,long mtmuc, long nghiepvu, 
			long madt, long hoatdong,string mmyy, double fsno, double fsco) 
		{
			table = user+"." + table + mmyy.Substring(2);
			string mm = mmyy.Substring(0, 2);
			/*
			long value=-1;
			foreach(DataRow r in get_data("select * from a_dmtk where id="+stka).Tables[0].Rows)
			{
				if (int.Parse(r["chuong"].ToString())==0) chuong=value;
				if (int.Parse(r["loaikhoan"].ToString())==0) lk=value;
				if (int.Parse(r["nghiepvu"].ToString())==0) nghiepvu=value;
				if (int.Parse(r["congno"].ToString())==0) madt=value;
				if (int.Parse(r["loaikm"].ToString())==0) khoanmuc=value;
				if (int.Parse(r["mlns"].ToString())==0) mtmuc=value;
				if (int.Parse(r["hoatdong"].ToString())==0) hoatdong=value;
			}*/			
			sql = "update " + table + " set fsno" + mm + "=fsno" + mm + "+"+fsno+",fsco"+ mm + "=fsco" + mm + "+"+fsco;
			sql+=" where idbc="+idbc+" and chuong="+chuong;
			sql+=" and lk="+lk+" and stka="+stka+" and khoanmuc="+khoanmuc;
			sql+=" and khoanmuc2="+khoanmuc2+" and khoanmuc3="+khoanmuc3+" and khoanmuc4="+khoanmuc4+" and mtmuc="+mtmuc;
			sql+=" and nghiepvu="+nghiepvu+" and madt="+madt+" and hoatdong="+hoatdong;
			con=new OracleConnection(sConn);
			try 
			{			
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql = "INSERT INTO "+ table	+ " (idbc,chuong,lk,stka,khoanmuc,khoanmuc2,khoanmuc3,khoanmuc4,mtmuc,nghiepvu,madt,hoatdong,";
					sql += "fsno" + mm + ",fsco" + mm + ")";
					sql += " values ("+idbc+","+chuong+","+lk+","+stka+","+khoanmuc+","+khoanmuc2+","+khoanmuc3+","+khoanmuc4+","+mtmuc+","+nghiepvu+","+madt+","+hoatdong;
					sql+=","+fsno+","+fsco+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					irec=cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			} 
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool updFb(long idbc,long chuong, long lk, long tkno, long tkco, long kmno,long kmco,
			long kmno2,long kmco2,long kmno3,long kmco3,long kmno4,long kmco4,long hoatdong, 
			long nghiepvu, string mmyy, double stien) 
		{
			string table = user+".a_fb" + mmyy.Substring(2), mm = mmyy.Substring(0, 2);
			sql = "update " + table + " set fs" + mm + "=fs" + mm+ "+"+stien+" where idbc="+idbc+" and chuong="+chuong;
			sql+= " and lk="+lk+" and tkno="+tkno+" and tkco="+tkco+" and kmno="+kmno+" and kmco="+kmco;
			sql+= " and kmno2="+kmno2+" and kmco2="+kmco2+" and kmno3="+kmno3+" and kmco3="+kmco3+" and kmno4="+kmno4+" and kmco4="+kmco4;
			sql+= " and hoatdong="+hoatdong+" and nghiepvu="+nghiepvu;
			con=new OracleConnection(sConn);
			try 
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql = "INSERT INTO " + table + " (idbc,chuong,lk,tkno,tkco,kmno,kmco,kmno2,kmco2,kmno3,kmco3,kmno4,kmco4,hoatdong,nghiepvu,";
					sql += "fs" + mm + ")";
					sql += " values ("+idbc+","+chuong+","+lk+","+tkno+","+tkco+","+kmno+","+kmco+","+kmno2+","+kmco2+","+kmno3+","+kmco3+","+kmno4+","+kmco4+","+hoatdong+","+nghiepvu;
					sql += ","+stien+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					irec=cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			} 
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		#region hamnhapctcu
		public bool updCt(string mmyy,long id,int idbc,string mact,int chuong,int chucnang,int hoatdong,int lctug,string soctg,
			string ngayg,string ngaygs,string noidung,long tknoa,long tkcoa,int loaidt,long madt,
			decimal stien,decimal nguyente,string thanggs,int nghiepvu,int loaibk,int tcnkp,long hopdong,
			string ctgs,long iddongthoi,int userid)
		{
			string table=user+".a_ct"+mmyy.Substring(2);
			sql="update "+table+" set idbc="+idbc+",mact='"+mact+"',chuong="+chuong+",chucnang="+chucnang+",hoatdong="+hoatdong+",lctug="+lctug;
			sql+=",soctg='"+soctg+"',ngayg=to_date('"+ngayg+"','dd/mm/yyyy')";
			sql+=",ngaygs=to_date('"+ngaygs+"','dd/mm/yyyy'),noidung=:noidung,tknoa="+tknoa+",tkcoa="+tkcoa;
			sql+=",loaidt="+loaidt+",madt="+madt+",stien="+stien;
			sql+=",nguyente="+nguyente+",thanggs='"+thanggs+"',nghiepvu="+nghiepvu+",loaibk="+loaibk;
			sql+=",tcnkp="+tcnkp+",hopdong="+hopdong+",ctgs='"+ctgs+"'";
			sql+=",iddongthoi="+iddongthoi+",userid="+userid+" where id="+id;
			con=new OracleConnection(sConn);
			try 
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("noidung", OracleType.NVarChar,254).Value = noidung;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="INSERT INTO "+table+" (id,idbc,mact,chuong,chucnang,hoatdong,lctug,soctg,ngayg,ngaygs,noidung,tknoa,tkcoa,";
					sql+="loaidt,madt,stien,nguyente,thanggs,nghiepvu,loaibk,tcnkp,hopdong,ctgs,iddongthoi,userid)";
					sql+=" VALUES("+id+","+idbc+",'"+mact+"',"+chuong+","+chucnang+","+hoatdong+","+lctug+",'"+soctg+"',to_date('"+ngayg+"','dd/mm/yyyy')";
					sql+=",to_date('"+ngaygs+"','dd/mm/yyyy'),:noidung,"+tknoa+","+tkcoa;
					sql+=","+loaidt+","+madt+","+stien+","+nguyente+",'"+thanggs+"',"+nghiepvu+","+loaibk+","+tcnkp;
					sql+=","+hopdong+",'"+ctgs+"',"+iddongthoi+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("noidung", OracleType.NVarChar,254).Value = noidung;
					irec=cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			} 
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}
		#endregion 

		public bool updCtct(string mmyy,long id,long idct,int stt,int lk,string noidung,long tknoa,long tkcoa,
			long kmno,long kmco,long kmno2,long kmco2,long kmno3,long kmco3,long kmno4,long kmco4,
			long mtmno,long mtmco,decimal stien,decimal nguyente,long ngoaite,decimal tygia,
			int tonghop,long mapt,int capphat,int lctug,string soctg,string ngayg,int chuong,long hopdong,int nghiepvu,
			long madt,int hoatdong,int userid)
		{
			string table=user+".a_ctct"+mmyy.Substring(2);
			sql="update "+table+" set idct="+idct+",stt="+stt+",lk="+lk+",noidung=:noidung";
			sql+=",tknoa="+tknoa+",tkcoa="+tkcoa+",kmno="+kmno+",kmco="+kmco;
			sql+=",kmno2="+kmno2+",kmco2="+kmco2+",kmno3="+kmno3+",kmco3="+kmco3+",kmno4="+kmno4+",kmco4="+kmco4;
			sql+=",mtmno="+mtmno+",mtmco="+mtmco;
			sql+=",stien="+stien+",nguyente="+nguyente+",ngoaite="+ngoaite+",tygia="+tygia;
			sql+=",tonghop="+tonghop+",mapt="+mapt+",capphat="+capphat+" where id="+id;
			con=new OracleConnection(sConn);
			try 
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("noidung", OracleType.NVarChar,254).Value = noidung;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="INSERT INTO "+table+" (id,idct,stt,lk,noidung,tknoa,tkcoa,kmno,kmco,kmno2,kmco2,kmno3,kmco3,kmno4,kmco4,mtmno,mtmco,stien";
					sql+=",nguyente,ngoaite,tygia,tonghop,mapt,capphat)";
					sql+=" VALUES("+id+","+idct+","+stt+","+lk+",:noidung,"+tknoa+","+tkcoa+","+kmno+","+kmco+","+kmno2+","+kmco2+","+kmno3+","+kmco3+","+kmno4+","+kmco4+","+mtmno+","+mtmco+","+stien;
					sql+=","+nguyente+","+ngoaite+","+tygia+","+tonghop+","+mapt+","+capphat+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("noidung", OracleType.NVarChar,254).Value = noidung;
					irec=cmd.ExecuteNonQuery();
					cmd.Dispose();
					/*
					if (tonghop==1)
					{
						updSodu("a_sd",insert,mmyy,chuong,hopdong,lk,nghiepvu,madt,tknoa,tkcoa,kmno,kmco,mtmno,mtmco,hoatdong,stien);
						updSodu("a_sdc",insert,mmyy,chuong,hopdong,lk,nghiepvu,madt,tknoa,tkcoa,kmno,kmco,mtmno,mtmco,hoatdong,stien);
					}*/
				}
			} 
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
				/*
				if (bChophanbo(tknoa,tkcoa))
					updPhanbo("a_phanbochua",insert,id,idct,lctug,soctg,ngayg,tknoa,tkcoa,"",noidung,1,stien,nghiepvu,mmyy,userid);
					*/
			}
			return true;
		}
		public bool updCtk(string mmyy,long id,string tendt,string diachi)
		{
			string table=user+".a_ctk"+mmyy.Substring(2);
			sql="update "+table+" set tendt=:tendt,diachi=:diachi where id="+id;
			con=new OracleConnection(sConn);
			try 
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("tendt", OracleType.NVarChar,254).Value = tendt;
				cmd.Parameters.Add("diachi", OracleType.NVarChar,254).Value = diachi;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="INSERT INTO "+table+" (id,tendt,diachi)";
					sql+=" VALUES("+id+",:tendt,:diachi)";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("tendt", OracleType.NVarChar,254).Value = tendt;
					cmd.Parameters.Add("diachi", OracleType.NVarChar,254).Value = diachi;
					irec=cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			} 
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool updCtbk(string mmyy,long id,int loaihd,string mauso,string kyhieu,string sohd,string ngayhd,
			decimal thuexuat,decimal tienthue)
		{
			string table=user+".a_ctbk"+mmyy.Substring(2);
			sql="update "+table+" set loaihd="+loaihd+",mauso='"+mauso+"',kyhieu='"+kyhieu+"',sohd='"+sohd+"'";
			sql+=",ngayhd=to_date('"+ngayhd+",'dd/mm/yyyy'),thuexuat="+thuexuat+",tienthue="+tienthue;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try 
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="INSERT INTO "+table+" (id,loaihd,mauso,kyhieu,sohd,ngayhd,thuexuat,tienthue)";
					sql+=" VALUES("+id+","+loaihd+",'"+mauso+"',"+kyhieu+"','"+sohd+"',to_date('"+ngayhd+"','dd/mm/yyyy'),"+thuexuat+","+tienthue+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					irec=cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			} 
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool updCtbkct(string mmyy,long id,int stt,int loaihd,string mauso,string kyhieu,string sohd,
			string ngayhd,string ten,string masothue,string noidung,decimal stien,decimal thuexuat,decimal tienthue)
		{
			string table=user+".a_ctbkct"+mmyy.Substring(2);
			sql="update "+table+" set loaihd="+loaihd+",mauso='"+mauso+"',kyhieu='"+kyhieu+"',sohd='"+sohd+"'";
			sql+=",ngayhd=to_date('"+ngayhd+"','dd/mm/yyyy')";
			sql+=",ten=:ten,masothue='"+masothue+"',noidung=:noidung,stien="+stien;
			sql+=",thuexuat="+thuexuat+",tienthue="+tienthue;
			sql+=" where id="+id+" and stt="+stt;
			con=new OracleConnection(sConn);
			try 
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				cmd.Parameters.Add("noidung", OracleType.NVarChar,254).Value = noidung;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="INSERT INTO "+table+" (id,stt,loaihd,mauso,kyhieu,sohd,";
					sql+="ngayhd,ten,masothue,noidung,stien,";
					sql+="thuexuat,tienthue)";
					sql+=" VALUES("+id+","+stt+","+loaihd+",'"+mauso+"','"+kyhieu+"','"+sohd+"'";
					sql+=",to_date('"+ngayhd+"','dd/mm/yyyy'),:ten,'"+masothue+"',:noidung,"+stien;
					sql+=","+thuexuat+","+tienthue+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					cmd.Parameters.Add("noidung", OracleType.NVarChar,254).Value = noidung;
					irec=cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			} 
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public int thanhtien_le
		{
			get
			{
				return 2;
			}
		}

		public bool bSophieu_tudong
		{
			get
			{
				ds=get_data("select ten from a_thongso where id=204");
				if (ds.Tables[0].Rows.Count==0) return false;
				return ds.Tables[0].Rows[0][0].ToString()=="1";
			}
		}

		public bool bSophieu_nam
		{
			get
			{
				ds=get_data("select ten from a_thongso where id=206");
				if (ds.Tables[0].Rows.Count==0) return false;
				return ds.Tables[0].Rows[0][0].ToString()=="1";
			}
		}

		public string giamdoc() 
		{
			try
			{
				return get_data("select ten from a_thongso where id=600").Tables[0].Rows[0]["ten"].ToString();
			}
			catch{return "";}
		}

		public string ketoantruong() 
		{
			try
			{
				return get_data("select ten from a_thongso where id=601").Tables[0].Rows[0]["ten"].ToString();
			}
			catch{return "";}
		}

		public string tienmat() 
		{
			try
			{
				return get_data("select ten from a_thongso where id=602").Tables[0].Rows[0]["ten"].ToString();
			}
			catch{return "";}
		}

		public string nganhang() 
		{
			try
			{
				return get_data("select ten from a_thongso where id=603").Tables[0].Rows[0]["ten"].ToString();
			}
			catch{return "";}
		}

		public string vattu() 
		{
			try
			{
				return get_data("select ten from a_thongso where id=604").Tables[0].Rows[0]["ten"].ToString();
			}
			catch{return "";}
		}

		public string hanghoa() 
		{
			try
			{
				return get_data("select ten from a_thongso where id=605").Tables[0].Rows[0]["ten"].ToString();
			}
			catch{return "";}
		}

		public string tonghop() 
		{
			try
			{
				return get_data("select ten from a_thongso where id=606").Tables[0].Rows[0]["ten"].ToString();
			}
			catch{return "";}
		}

		public string thuquy() 
		{
			try
			{
				return get_data("select ten from a_thongso where id=607").Tables[0].Rows[0]["ten"].ToString();
			}
			catch{return "";}
		}

		public int Ngaylv_Ngayht{get{return int.Parse(Thongso("c10"));}}		

		public string get_sophieu(string mmyy,string fie,string dk,int vt,int len)
		{
			int ret=1;
			string s="";
			for(int i=0;i<len;i++) s+="0";
			sql="select max(to_char(substr("+fie+","+vt+","+len+"),'"+s+"')) as so ";
			sql+=" from a_ct"+mmyy.Substring(2)+" a,a_ctct"+mmyy.Substring(2)+" b where a.id=b.idct and "+dk;
			ds=get_data(sql);
			if (ds.Tables[0].Rows.Count>0)
			{
				try
				{
					if (ds.Tables[0].Rows[0]["so"].ToString()!="") ret=int.Parse(ds.Tables[0].Rows[0]["so"].ToString())+1;
				}
				catch{}
			}
			return ret.ToString().PadLeft(len,'0');
		}

		public string get_ctgs(string mmyy,string fie,string dk,int vt,int len)
		{
			int ret=1;
			string s="";
			for(int i=0;i<len;i++) s+="0";
			sql="select max(to_char(substr("+fie+","+vt+","+len+"),'"+s+"')) as so ";
			sql+=" from a_ctgs"+mmyy.Substring(2)+" where "+dk;
			ds=get_data(sql);
			if (ds.Tables[0].Rows.Count>0)
			{
				try
				{
					if (ds.Tables[0].Rows[0]["so"].ToString()!="") ret=int.Parse(ds.Tables[0].Rows[0]["so"].ToString())+1;
				}
				catch{}
			}
			return ret.ToString().PadLeft(len,'0');
		}

		public int get_stt(DataTable dt)
		{
			if (dt.Rows.Count==0) return 1;
			else return int.Parse(dt.Rows[dt.Rows.Count-1]["stt"].ToString())+1;
		}

		public DataSet getPhantich(string stknoa, string mtmno,string stkcoa,string mtmco) 
		{
			sql = "select loai from a_dmtinhchat";
			sql += " where (loai<>-1)";
			if (stknoa!="" && stkcoa!="") 
			{
				sql += " and ((tknoa=substr('" + stknoa	+ "',1,length(tknoa)) and length(tknoa)>0";
				if (mtmno!="")	sql += " and mtmno=substr('" + mtmno + "',1,length(mtmno)) and length(mtmno)>0";
				sql += ")";
				sql += " or (tkcoa=substr('" + stkcoa + "',1,length(tkcoa)) and length(tkcoa)>0";
				if (mtmco!="")	sql += " and mtmco=substr('" + mtmco	+ "',1,length(mtmco)) and length(mtmco)>0";
				sql += "))";
			} 
			else if (stknoa!="") 
			{
				sql += " and (tknoa=substr('" + stknoa	+ "',1,length(tknoa)) and length(tknoa)>0";
				if (mtmno!="")	sql += " and mtmno=substr('" + mtmno	+ "',1,length(mtmno)) and length(mtmno)>0";
				sql += ")";
			} 
			else if (stkcoa!="") 
			{
				sql += " and (tkcoa=substr('" + stkcoa	+ "',1,length(tkcoa)) and length(tkcoa)>0";
				if (mtmco!="")	sql += " and mtmco=substr('" + mtmco	+ "',1,length(mtmco)) and length(mtmco)>0";
				sql += ")";
			} 
			else sql += " and (loai=-1)";
			int loai = -1;
			foreach(DataRow r in get_data(sql).Tables[0].Rows)
			{
				loai=int.Parse(r["loai"].ToString());
				break;
			}
			sql = "select * from a_phantich where tinhchat=" + loai	+ " and sudung=1 order by ten";
			return get_data(sql);
		}		

		public void updrec_ct(DataTable dt,long id,int idbc,string mact,int chuong,int hoatdong,int lctug,string soctg,string ngayg,
			string ngaygs,string noidung,long tknoa,long tkcoa,int loaidt,long madt,decimal stien,decimal nguyente,
			string thanggs,int nghiepvu,int loaibk,int tcnkp,int lanin,long hopdong,string ctgs,
			string stknoa,string stkcoa,string ttknoa,string ttkcoa,string mavt,string tendt,string diachi,string sohd,
			int loaihd,string kyhieu,string sobk,string ngaybk,decimal thuexuat,decimal tienthue,string tendtk,
			string diachik,string tenhoatdong,string sotaikhoan,string accountno,string accountco,string tennhno,
			string tennhco,string masothue,long iddongthoi)
		{
			string exp="id="+id;
			DataRow r = getrowbyid (dt,exp); 
			if ( r == null )
			{
				DataRow nrow = dt.NewRow ( ) ;
				nrow["id"]=id;
				nrow["idbc"]=idbc;
				nrow["mact"]=mact;
				nrow["chuong"] = chuong;
				nrow["hoatdong"] = hoatdong;
				nrow["lctug"] = lctug;
				nrow["soctg"] = soctg;
				nrow["ngayg"] = ngayg;
				nrow["ngaygs"] = ngaygs;
				nrow["noidung"] = noidung;
				nrow["tknoa"] = tknoa;
				nrow["tkcoa"] = tkcoa;
				nrow["loaidt"] = loaidt;
				nrow["madt"] = madt;
				nrow["stien"] = stien;
				nrow["nguyente"] = nguyente;
				nrow["thanggs"]=thanggs;
				nrow["nghiepvu"]=nghiepvu;
				nrow["loaibk"]=loaibk;
				nrow["tcnkp"]=tcnkp;
				nrow["lanin"]=lanin;
				nrow["hopdong"]=hopdong;
				nrow["ctgs"]=ctgs;
				nrow["stknoa"]=stknoa;
				nrow["stkcoa"]=stkcoa;
				nrow["ttknoa"]=ttknoa;
				nrow["ttkcoa"]=ttkcoa;
				nrow["mavt"]=mavt;
				nrow["tendt"] = tendt;
				nrow["diachi"]=diachi;
				nrow["loaihd"]=loaihd;
				nrow["kyhieu"]=kyhieu;
				nrow["sobk"]=sobk;
				nrow["ngaybk"]=ngaybk;
				nrow["thuexuat"]=thuexuat;
				nrow["tienthue"]=tienthue;
				nrow["tendtk"]=tendtk;
				nrow["diachik"]=diachik;
				nrow["tenhoatdong"]=tenhoatdong;
				nrow["sotaikhoan"]=sotaikhoan;
				nrow["accountno"]=accountno;
				nrow["accountco"]=accountco;
				nrow["tennhno"]=tennhno;
				nrow["tennhco"]=tennhco;
				nrow["masothue"]=masothue;
				nrow["iddongthoi"]=iddongthoi;
				dt.Rows.Add ( nrow ) ;
			}
			else
			{
				DataRow[] dr = dt.Select(exp);
				dr[0]["id"]=id;
				dr[0]["idbc"]=idbc;
				dr[0]["mact"]=mact;
				dr[0]["chuong"] = chuong;
				dr[0]["hoatdong"] = hoatdong;
				dr[0]["lctug"] = lctug;
				dr[0]["soctg"] = soctg;
				dr[0]["ngayg"] = ngayg;
				dr[0]["ngaygs"] = ngaygs;
				dr[0]["noidung"] = noidung;
				dr[0]["tknoa"] = tknoa;
				dr[0]["tkcoa"] = tkcoa;
				dr[0]["loaidt"] = loaidt;
				dr[0]["madt"] = madt;
				dr[0]["stien"] = stien;
				dr[0]["nguyente"] = nguyente;
				dr[0]["thanggs"]=thanggs;
				dr[0]["nghiepvu"]=nghiepvu;
				dr[0]["loaibk"]=loaibk;
				dr[0]["tcnkp"]=tcnkp;
				dr[0]["lanin"]=lanin;
				dr[0]["hopdong"]=hopdong;
				dr[0]["ctgs"]=ctgs;
				dr[0]["stknoa"]=stknoa;
				dr[0]["stkcoa"]=stkcoa;
				dr[0]["ttknoa"]=ttknoa;
				dr[0]["ttkcoa"]=ttkcoa;
				dr[0]["mavt"]=mavt;
				dr[0]["tendt"] = tendt;
				dr[0]["diachi"]=diachi;
				dr[0]["loaihd"]=loaihd;
				dr[0]["kyhieu"]=kyhieu;
				dr[0]["sobk"]=sobk;
				dr[0]["ngaybk"]=ngaybk;
				dr[0]["thuexuat"]=thuexuat;
				dr[0]["tienthue"]=tienthue;
				dr[0]["tendtk"]=tendtk;
				dr[0]["diachik"]=diachik;
				dr[0]["tenhoatdong"]=tenhoatdong;
				dr[0]["sotaikhoan"]=sotaikhoan;
				dr[0]["accountno"]=accountno;
				dr[0]["accountco"]=accountco;
				dr[0]["tennhno"]=tennhno;
				dr[0]["tennhco"]=tennhco;
				dr[0]["masothue"]=masothue;
				dr[0]["iddongthoi"]=iddongthoi;
			}
		}

		public void updrec_ctct(DataTable dt,long id,decimal stt,int lk,string noidung,long tknoa,long tkcoa,
			int kmno,int kmco,int kmno2,int kmco2,int kmno3,int kmco3,int kmno4,int kmco4,long mtmno,long mtmco,decimal stien,decimal nguyente,long ngoaite,decimal tygia,
			string mangoaite,int tonghop,long mapt,string ctgs,string tenlk,string stknoa,string stkcoa,string stkmtmno,
			string stkmtmco,string tenpt,string tenkmno,string tenkmco,int capphat,string tencapphat,string thangqt)
		{
			string exp="id="+id;
			DataRow r = getrowbyid (dt,exp); 
			if ( r == null )
			{
				DataRow nrow = dt.NewRow ( ) ;
				nrow["id"]=id;
				nrow["stt"] = stt;
				nrow["lk"] = lk;
				nrow["noidung"] = noidung;
				nrow["tknoa"] = tknoa;
				nrow["tkcoa"] = tkcoa;
				nrow["kmno"] = kmno;
				nrow["kmco"] = kmco;
				nrow["kmno2"] = kmno2;
				nrow["kmco2"] = kmco2;
				nrow["kmno3"] = kmno3;
				nrow["kmco3"] = kmco3;
				nrow["kmno4"] = kmno4;
				nrow["kmco4"] = kmco4;
				nrow["mtmno"] = mtmno;
				nrow["mtmco"] = mtmco;
				nrow["stien"] = stien;
				nrow["nguyente"] = nguyente;
				nrow["ngoaite"] = ngoaite;
				nrow["tygia"] = tygia;
				nrow["mangoaite"]=mangoaite;
				nrow["tonghop"]=tonghop;
				nrow["mapt"]=mapt;
				nrow["ctgs"]=ctgs;
				nrow["tenlk"]=tenlk;
				nrow["stknoa"]=stknoa;
				nrow["stkcoa"]=stkcoa;
				nrow["stkmtmno"]=stkmtmno;
				nrow["stkmtmco"]=stkmtmco;
				nrow["tenpt"]=tenpt;
				nrow["tenkmno"]=tenkmno;
				nrow["tenkmco"]=tenkmco;
				nrow["capphat"] = capphat;
				nrow["tencapphat"]=tencapphat;
				nrow["thangqt"]=thangqt;
				dt.Rows.Add ( nrow ) ;
			}
			else
			{
				DataRow[] dr = dt.Select(exp);
				dr[0]["id"]=id;
				dr[0]["stt"] = stt;
				dr[0]["lk"] = lk;
				dr[0]["noidung"] = noidung;
				dr[0]["tknoa"] = tknoa;
				dr[0]["tkcoa"] = tkcoa;
				dr[0]["kmno"] = kmno;
				dr[0]["kmco"] = kmco;
				dr[0]["kmno2"] = kmno2;
				dr[0]["kmco2"] = kmco2;
				dr[0]["kmno3"] = kmno3;
				dr[0]["kmco3"] = kmco3;
				dr[0]["kmno4"] = kmno4;
				dr[0]["kmco4"] = kmco4;
				dr[0]["mtmno"] = mtmno;
				dr[0]["mtmco"] = mtmco;
				dr[0]["stien"] = stien;
				dr[0]["nguyente"] = nguyente;
				dr[0]["ngoaite"] = ngoaite;
				dr[0]["tygia"] = tygia;
				dr[0]["mangoaite"]=mangoaite;
				dr[0]["tonghop"]=tonghop;
				dr[0]["mapt"]=mapt;
				dr[0]["ctgs"]=ctgs;
				dr[0]["tenlk"]=tenlk;
				dr[0]["stknoa"]=stknoa;
				dr[0]["stkcoa"]=stkcoa;
				dr[0]["stkmtmno"]=stkmtmno;
				dr[0]["stkmtmco"]=stkmtmco;
				dr[0]["tenpt"]=tenpt;
				dr[0]["tenkmno"]=tenkmno;
				dr[0]["tenkmco"]=tenkmco;
				dr[0]["capphat"] = capphat;
				dr[0]["tencapphat"]=tencapphat;
				dr[0]["thangqt"]=thangqt;
			}
		}
		
		public void updrec_so(DataTable dt,long id,int chuong,int lk,long stka,int khoanmuc,int khoanmuc2,int khoanmuc3,
			int khoanmuc4,long mtmuc,int nghiepvu,
			int hoatdong,decimal sdnont,decimal sdcont,decimal sdno,decimal sdco,long ngoaite,decimal tygia,
			string tenlk,string stk,string stkmtm,string tenkhoanmuc,string tenkhoanmuc2,string tenkhoanmuc3,string tenkhoanmuc4)
		{
			string exp="id="+id;
			DataRow r = getrowbyid (dt,exp); 
			if ( r == null )
			{
				DataRow nrow = dt.NewRow ( ) ;
				nrow["id"]=id;
				nrow["chuong"] = chuong;
				nrow["lk"] = lk;
				nrow["stka"] = stka;
				nrow["khoanmuc"] = khoanmuc;
				nrow["khoanmuc2"] = khoanmuc2;
				nrow["khoanmuc3"] = khoanmuc3;
				nrow["khoanmuc4"] = khoanmuc4;
				nrow["mtmuc"] = mtmuc;
				nrow["nghiepvu"] = nghiepvu;
				nrow["hoatdong"] = hoatdong;
				nrow["sdnont01"] = sdnont;
				nrow["sdcont01"] = sdcont;
				nrow["sdno01"] = sdno;
				nrow["sdco01"] = sdco;
				nrow["ngoaite"] = ngoaite;
				nrow["tygia"] = tygia;
				nrow["tenlk"]=tenlk;
				nrow["stkmtm"]=stkmtm;
				nrow["tenkhoanmuc"]=tenkhoanmuc;
				nrow["tenkhoanmuc2"]=tenkhoanmuc2;
				nrow["tenkhoanmuc3"]=tenkhoanmuc3;
				nrow["tenkhoanmuc4"]=tenkhoanmuc4;
				dt.Rows.Add ( nrow ) ;
			}
			else
			{
				DataRow[] dr = dt.Select(exp);
				dr[0]["id"]=id;
				dr[0]["chuong"] = chuong;
				dr[0]["lk"] = lk;
				dr[0]["stka"] = stka;
				dr[0]["khoanmuc"] = khoanmuc;
				dr[0]["khoanmuc2"] = khoanmuc2;
				dr[0]["khoanmuc3"] = khoanmuc3;
				dr[0]["khoanmuc4"] = khoanmuc4;
				dr[0]["mtmuc"] = mtmuc;
				dr[0]["nghiepvu"] = nghiepvu;
				dr[0]["hoatdong"] = hoatdong;
				dr[0]["sdnont01"] = sdnont;
				dr[0]["sdcont01"] = sdcont;
				dr[0]["sdno01"] = sdno;
				dr[0]["sdco01"] = sdco;
				dr[0]["ngoaite"] = ngoaite;
				dr[0]["tygia"] = tygia;
				dr[0]["tenlk"]=tenlk;
				dr[0]["stkmtm"]=stkmtm;
				dr[0]["tenkhoanmuc"]=tenkhoanmuc;
				dr[0]["tenkhoanmuc2"]=tenkhoanmuc2;
				dr[0]["tenkhoanmuc3"]=tenkhoanmuc3;
				dr[0]["tenkhoanmuc4"]=tenkhoanmuc4;
			}
		}
		public void updDtsd(string den) 
		{
			string _tu = "";//, _den = "";
			sql = "select * from a_dtsd where substr(mmyy,1,2)<='" + den.Substring(0,2) + "' and substr(mmyy,3,2)='"+den.Substring(2)+"' order by mmyy";
			foreach(DataRow r in get_data(sql).Tables[0].Rows)
			{
				if (_tu=="") _tu = r["mmyy"].ToString();
				//_den = r["mmyy"].ToString();
				//if (_tu!="" && _den!="") KiemtraFb(_tu, den, -1);
				break;
			} 
			if (_tu!="") KiemtraFb(_tu, den, -1);
		}

		public DataSet rCandoitk(int chuong,int hoatdong,int lk,string tu,string den,bool chitiet) 
		{   
			string sql="",yy=tu.Substring(2);
			updDtsd(den);
			int m1=int.Parse(tu.Substring(0,2)),m2=int.Parse(den.Substring(0,2));
			sql="select b.stk,a.* from a_sd"+yy+" a,a_dmtk b where a.stka=b.id ";
			if (chuong!=-1) sql+=" and a.chuong="+chuong;
			if (hoatdong!=-1) sql+=" and a.hoatdong="+hoatdong;
			if (lk!=-1) sql+=" and a.lk="+lk;
			sql+=" order by b.tknb,b.stk";
			DataTable dt=get_data(sql).Tables[0];
			sql="select tknb,id,stk,ttk,sp,tinhchat,tonghop,bcdtk,";
			sql+="so as sddco,so as sddno,so as psno,";
			sql+="so as psco,so as lkno,so as lkco,";
			sql+="so as sdcno,so as sdcco from a_dmtk order by tknb,stk";
			DataTable dt1=get_data(sql).Tables[0];
			foreach(DataRow r in dt1.Rows)
			{
				r["sddno"]=getSd(dt, m1,r["stk"].ToString(),"sdno");
				r["sddco"]=getSd(dt, m1,r["stk"].ToString(),"sdco");
				r["psno"]=getFs(dt, m1, m2,r["stk"].ToString(),"fsno");
				r["psco"]=getFs(dt, m1, m2,r["stk"].ToString(),"fsco");
				if(m1>1)
				{
					r["lkno"]=getFs(dt, 1, m2,r["stk"].ToString(),"fsno");    			
					r["lkco"]=getFs(dt, 1, m2,r["stk"].ToString(),"fsco");
				}
				else
				{
					r["lkno"]=r["psno"].ToString();
					r["lkco"]=r["psco"].ToString();
				}
			}
			decimal sddno,sddco,sdcno,sdcco,min;
			foreach(DataRow r in dt1.Rows)
			{
				switch (int.Parse(r["tinhchat"].ToString()))
				{
					case 1://tkno
						sddno=decimal.Parse(r["sddno"].ToString())-decimal.Parse(r["sddco"].ToString());
						sddco=0;
						sdcno=sddno+decimal.Parse(r["psno"].ToString())-decimal.Parse(r["psco"].ToString());
						sdcco=0;        				
						break;
					case 2: //tkco
						sddno=0;
						sddco=decimal.Parse(r["sddco"].ToString())-decimal.Parse(r["sddno"].ToString());
						sdcno=0;
						sdcco=sddco+decimal.Parse(r["psco"].ToString())-decimal.Parse(r["psno"].ToString());
						break;
					default : 
						min=Math.Min(decimal.Parse(r["sddno"].ToString()),decimal.Parse(r["sddco"].ToString()));
						sddno=decimal.Parse(r["sddno"].ToString())-min;
						sddco=decimal.Parse(r["sddco"].ToString())-min;
						min=Math.Min(sddno+decimal.Parse(r["psno"].ToString()),sddco+decimal.Parse(r["psco"].ToString()));
						sdcno=sddno+decimal.Parse(r["psno"].ToString())-min;
						sdcco=sddco+decimal.Parse(r["psco"].ToString())-min;
						break;
				}         		
				r["sddno"]=sddno;
				r["sddco"]=sddco;
				r["sdcno"]=sdcno;
				r["sdcco"]=sdcco;
				/*
				if (!chitiet)
				{
					if (int.Parse(r["bcdtk"].ToString())==0 || (sddno==0 && sddco==0 && sdcno==0 && sdcco==0 
						&& decimal.Parse(r["psno"].ToString())==0 && decimal.Parse(r["psco"].ToString())==0 
						&& decimal.Parse(r["lkno"].ToString())==0 && decimal.Parse(r["lkco"].ToString())==0)) 
						r.Delete();
				}
				else if (sddno==0 && sddco==0 && sdcno==0 && sdcco==0 && decimal.Parse(r["psno"].ToString())==0 
					&& decimal.Parse(r["psco"].ToString())==0 && decimal.Parse(r["lkno"].ToString())==0 
					&& decimal.Parse(r["lkco"].ToString())==0)
				{
					r.Delete();
				}*/
			}
			dt1.AcceptChanges();
			ds=new DataSet();
			ds.ReadXml("..\\..\\..\\xml\\a_candoitk.xml");
			DataRow r1;
			string tentknb="";
			bool bSkip=false;
			foreach(DataRow r in dt1.Rows)
			{
				bSkip=false;
				if (!chitiet)
				{
					if (int.Parse(r["bcdtk"].ToString())==0 || 
						(decimal.Parse(r["sddno"].ToString())==0 && decimal.Parse(r["sddco"].ToString())==0 
						&& decimal.Parse(r["sdcno"].ToString())==0 && decimal.Parse(r["sdcco"].ToString())==0 
						&& decimal.Parse(r["psno"].ToString())==0 && decimal.Parse(r["psco"].ToString())==0 
						&& decimal.Parse(r["lkno"].ToString())==0 && decimal.Parse(r["lkco"].ToString())==0)) 
						bSkip=true;
				}
				else if (
					decimal.Parse(r["sddno"].ToString())==0 && decimal.Parse(r["sddco"].ToString())==0 
					&& decimal.Parse(r["sdcno"].ToString())==0 && decimal.Parse(r["sdcco"].ToString())==0 
					&& decimal.Parse(r["psno"].ToString())==0 
					&& decimal.Parse(r["psco"].ToString())==0 && decimal.Parse(r["lkno"].ToString())==0 
					&& decimal.Parse(r["lkco"].ToString())==0)
				{
					bSkip=true;
				}
				if (!bSkip)
				{
					if(int.Parse(r["tknb"].ToString())==0) tentknb="A.CÁC TÀI KHOẢN TRONG BẢNG";
					else tentknb="B.CÁC TÀI KHOẢN NGOÀI BẢNG";
					r1=ds.Tables[0].NewRow();
					r1["tentknb"]=tentknb;
					r1["tknb"]=r["tknb"];
					r1["id"]=r["id"];
					r1["stk"]=" ".PadLeft(int.Parse(r["sp"].ToString()),' ')+r["stk"].ToString();
					r1["ttk"]=r["ttk"];
					r1["sp"]=r["sp"];
					r1["tinhchat"]=r["tinhchat"];
					r1["tonghop"]=r["tonghop"];
					r1["bcdtk"]=r["bcdtk"];
					r1["sddno"]=r["sddno"];
					r1["sddco"]=r["sddco"];
					r1["psno"]=r["psno"];
					r1["psco"]=r["psco"];
					r1["lkno"]=r["lkno"];
					r1["lkco"]=r["lkco"];
					r1["sdcno"]=r["sdcno"];
					r1["sdcco"]=r["sdcco"];                
					ds.Tables[0].Rows.Add(r1);				
				}
			}
			return ds;
		}       
		public decimal getSd(DataTable dt, int m1, string stk, string fie) 
		{
			decimal st = 0;
			string f = fie + m1.ToString().PadLeft(2,'0');//, so = "";
			int l = Math.Max(stk.Trim().Length-1,0);
			foreach(DataRow r in dt.Select("substring(stk,1,"+stk.Trim().Length+")='"+stk.Trim()+"'"))
			{
				if (r["stk"].ToString().Trim().IndexOf(stk.Trim())!=-1)
				{
					//if (so=="") so = r["stk"].ToString().Trim().Substring(0, l);
					st += decimal.Parse(r[f].ToString());
				}
			}
			return st;
		}

		public decimal getFs(DataTable dt, int m1, int m2, string stk,string fie) 
		{
			decimal st = 0;
			string f = "", so = "";
			int l = Math.Max(stk.Trim().Length-1,0);
			foreach(DataRow r in dt.Select("substring(stk,1,"+stk.Trim().Length+")='"+stk.Trim()+"'"))
			{
				if (r["stk"].ToString().Trim().IndexOf(stk.Trim())!=-1)
				{
					/*if (so=="") 
					{
						so = r["stk"].ToString().Trim().Substring(0, l);
						st = 0;
					}*/
					for (int i = m1; i <= m2; i++) 
					{
						f = fie + i.ToString().PadLeft(2,'0');
						st += decimal.Parse(r[f].ToString());
					}
				}
			}
			return st;
		}

		private string Sotk(string s)
		{
			string s1="";
			if (s==null) return s1;
			else
			{
				int l=s.Trim().Length;
				for(int i=0;i<l;i++)
				{
					s1+=s.Substring(i,1)+"".PadLeft(3,' ');
				}
			}
			return s1;
		}

		public DataSet phieuthuchi(string mmyy,long id)
		{
			doiso.Doisototext doiso=new doiso.Doisototext();
			string usr=user;
			string sql="select a.mact,a.soctg,to_char(a.ngayg,'dd/mm/yyyy') as ngayg,f.stk as tkno,";
			sql+="g.stk as tkco,case when c.id is null then case when d.loaidt=0 then d.daidien else d.tendt end else null end as tendt,";
			sql+="case when c.id is null then d.diachi else c.diachi end as diachi,a.noidung,";
			sql+="case when c.id is null then  nvl(d.daidien,d.tendt) else c.tendt end as daidien,"; 
			sql+=" b.stien,e.ten as tieude,a.ctgs,h.ma as ngoaite,d.madvqhns,i.tenkp,d.sotaikhoan,d.nganhang";
			sql+=" from "+usr+".a_ct"+mmyy.Substring(2)+" a inner join "+usr+".a_ctct"+mmyy.Substring(2)+" b on a.id=b.idct ";
			sql+=" left join "+usr+".a_ctk"+mmyy.Substring(2)+" c on a.id=c.id ";
			sql+=" left join "+usr+".a_dmdt d on a.madt=d.id ";
			sql+=" inner join "+usr+".a_bcnghang e on a.lctug=e.id ";
			sql+=" left join "+usr+".a_dmtk f on b.tknoa=f.id ";
			sql+=" left join "+usr+".a_dmtk g on b.tkcoa=g.id ";
			sql+=" left join "+usr+".a_dmngoaite h on b.ngoaite=h.id ";
			sql+=" left join "+usr+".a_btdkp i on d.makp=i.id ";
			sql+=" where a.id="+id+" order by b.stt";
			string so="",ngay="",tkno="",tkco="",tendt="",diachi="",noidung="",tieude="",soctg="",daidien="",ngoaite="",madvqhns="",mact="",tenkp="",sotaikhoan="",nganhang="";
			long stien=0;
			foreach(DataRow r in get_data(sql).Tables[0].Rows)
			{
				so=r["soctg"].ToString();
				ngay=r["ngayg"].ToString();
				if (tkno.IndexOf(r["tkno"].ToString())==-1) tkno+=r["tkno"].ToString().Trim()+",";
				if (tkco.IndexOf(r["tkco"].ToString())==-1) tkco+=r["tkco"].ToString().Trim()+",";
				tendt=r["tendt"].ToString();
				diachi=r["diachi"].ToString();
				noidung=r["noidung"].ToString().Trim();
				stien+=long.Parse(r["stien"].ToString());
				tieude=r["tieude"].ToString();
				soctg=r["ctgs"].ToString();
				daidien=r["daidien"].ToString();
				ngoaite=r["ngoaite"].ToString();
				madvqhns=r["madvqhns"].ToString();
				mact=r["mact"].ToString();
				tenkp=r["tenkp"].ToString();
				sotaikhoan=r["sotaikhoan"].ToString();
				nganhang=r["nganhang"].ToString();
			}
			string _tienmat=tienmat(),_thuquy=thuquy(),_ketoantruong=ketoantruong();
			DataSet ds1=new DataSet();
			ds1=get_data("select 0 as id from dual");
			ds1.Tables[0].Columns.Add("soyte");
			ds1.Tables[0].Columns.Add("benhvien");
			ds1.Tables[0].Columns.Add("diachibv");
			ds1.Tables[0].Columns.Add("madvqhnsbv");
			ds1.Tables[0].Columns.Add("tenkp");
			ds1.Tables[0].Columns.Add("tieude");
			ds1.Tables[0].Columns.Add("soct");
			ds1.Tables[0].Columns.Add("ngayct");
			ds1.Tables[0].Columns.Add("no");
			ds1.Tables[0].Columns.Add("co");
			ds1.Tables[0].Columns.Add("hoten");
			ds1.Tables[0].Columns.Add("diachi");
			ds1.Tables[0].Columns.Add("noidung");
			ds1.Tables[0].Columns.Add("daidien");
			ds1.Tables[0].Columns.Add("sotien",typeof(decimal));
			ds1.Tables[0].Columns.Add("bangchu");			
			ds1.Tables[0].Columns.Add("soctgoc");
			ds1.Tables[0].Columns.Add("lapbieu");
			ds1.Tables[0].Columns.Add("noptien");
			ds1.Tables[0].Columns.Add("thuquy");
			ds1.Tables[0].Columns.Add("ketoantruong");
			ds1.Tables[0].Columns.Add("giamdoc");
			ds1.Tables[0].Columns.Add("ngoaite");
			ds1.Tables[0].Columns.Add("madvqhns");
			ds1.Tables[0].Columns.Add("sotaikhoan");
			ds1.Tables[0].Columns.Add("nganhang");
			ds1.Tables[0].Columns.Add("mact");
			DataRow [] r1=ds1.Tables[0].Select("id=0");
			r1[0]["soyte"]=Syte;
			r1[0]["benhvien"]=Tenbv;
			r1[0]["diachibv"]=Diachi;
			r1[0]["madvqhnsbv"]=Madvqhns;
			r1[0]["tieude"]=tieude;
			r1[0]["tenkp"]=tenkp;
			r1[0]["soct"]=so;
			r1[0]["ngayct"]=ngay;
			r1[0]["no"]=tkno;
			r1[0]["co"]=tkco;
			r1[0]["hoten"]=tendt;
			r1[0]["diachi"]=diachi;
			r1[0]["noidung"]=noidung;
			r1[0]["daidien"]=daidien;
			r1[0]["sotien"]=stien;
			r1[0]["bangchu"]=doiso.Doiso_Unicode(stien.ToString("#################"));
			r1[0]["soctgoc"]=soctg;
			r1[0]["lapbieu"]=_tienmat;
			r1[0]["noptien"]="";
			r1[0]["thuquy"]=_thuquy;
			r1[0]["ketoantruong"]=_ketoantruong;
			r1[0]["giamdoc"]=giamdoc();
			r1[0]["ngoaite"]=ngoaite;
			r1[0]["madvqhns"]=madvqhns;
			r1[0]["mact"]=mact;
			r1[0]["sotaikhoan"]=sotaikhoan;
			r1[0]["nganhang"]=nganhang;
			ds1.AcceptChanges();
			return ds1;
		}
	
		public DataSet phieulinh(string mmyy,long id)
		{
			doiso.Doisototext doiso=new doiso.Doisototext();
			string usr=user;
			string sql="select a.mact,";
			sql+=" case when substr(trim(tkco.stk),7,length(trim(tkco.stk))) is not null";
			sql+=" then substr(trim(tkco.stk),7,length(trim(tkco.stk))) else ";
			sql+=" (case when substr(trim(tkno.stk),7,length(trim(tkno.stk))) is not null";
			sql+=" then substr(trim(tkno.stk),7,length(trim(tkno.stk))) else '' end) end as nguonkp,";
			sql+=" a.soctg,to_char(a.ngayg,'dd/mm/yyyy') as ngayg,";
			sql+=" case when s.account is null then t.account else s.account end as stkno,";
			sql+=" case when s.tennh is null then t.tennh else s.tennh end as tennh,";
			sql+=" case when c.id is null then d.tendt else c.tendt end as hoten,";
			sql+=" case when c.id is null then d.diachi else c.diachi end as diachi,";
			sql+=" case when d.sotaikhoan is null then '' else d.sotaikhoan end as stk_dmdt,";
			sql+=" d.nganhang as nganhang_dt, ";
			sql+=" d.socmnd,d.noicap,to_char(d.capngay,'dd/mm/yyyy') as capngay,";
			sql+=" b.noidung,b.stien,d.madvqhns,a.lctug,a.nghiepvu,x.ma as machuong,x.ten as chuong,";
			sql+=" y.lk,z.stk as mtmno,w.stk as mtmco,ns.mans as manns,ns.tenns as tennns,ns.mada as mada,ns.tenda as tenda ";
			sql+=" from "+usr+".a_ct"+mmyy.Substring(2)+" a inner join "+usr+".a_ctct"+mmyy.Substring(2)+" b on a.id=b.idct ";
			sql+=" inner join "+usr+".a_dmtk tkno on b.tknoa=tkno.id";
			sql+=" inner join "+usr+".a_dmtk tkco on b.tkcoa=tkco.id";
			sql+=" left join "+usr+".a_ctk"+mmyy.Substring(2)+" c on a.id=c.id ";
			sql+=" left join "+usr+".a_dmdt d on a.madt=d.id ";
			sql+=" inner join "+usr+".a_bcnghang e on a.lctug=e.id ";
			sql+=" left join "+usr+".a_dmnh s on a.tknoa=s.stk ";
			sql+=" left join "+usr+".a_dmnh t on a.tkcoa=t.stk ";
			sql+=" left join "+usr+".a_dmchuong x on a.chuong=x.id ";
			sql+=" left join "+usr+".a_dmlk y on b.lk=y.id ";
			sql+=" left join "+usr+".a_dmch z on b.mtmno=z.id ";
			sql+=" left join "+usr+".a_dmch w on b.mtmco=w.id ";
			sql+=" left join "+user+".a_dmngns ns on a.manns=ns.id ";
			sql+=" where a.id="+id+" order by b.stt";
			string so="",ngay="",stkno="",tai="",hoten="",diachi="",socmnd="",noicap="",capngay="",noidung="",madvqhns="",mact="";
			string machuong="",chuong="",lk="",mtmno="",mtmco="",nguonkp="",stk_dmdt = "",nganhang_dt="",manns="",tennns="",mada="",tenda="";
			int lctug=0,nghiepvu=0;
			long stien=0;
			DataSet ds1=new DataSet();
			ds1=get_data("select 0 as id from dual");
			ds1.Tables[0].Columns.Add("lctug",typeof(decimal));
			ds1.Tables[0].Columns.Add("nghiepvu",typeof(decimal));
			ds1.Tables[0].Columns.Add("nguonkp");
			ds1.Tables[0].Columns.Add("machuong");
			ds1.Tables[0].Columns.Add("chuong");
			ds1.Tables[0].Columns.Add("lk");
			ds1.Tables[0].Columns.Add("mtmno");
			ds1.Tables[0].Columns.Add("mtmco");
			ds1.Tables[0].Columns.Add("diachibv");
			ds1.Tables[0].Columns.Add("madvqhnsbv");
			ds1.Tables[0].Columns.Add("sotug");
			ds1.Tables[0].Columns.Add("ngayg");
			ds1.Tables[0].Columns.Add("stkno");
			ds1.Tables[0].Columns.Add("tentkno");
			ds1.Tables[0].Columns.Add("tai");
			ds1.Tables[0].Columns.Add("hoten");
			ds1.Tables[0].Columns.Add("diachi");
			ds1.Tables[0].Columns.Add("socmnd");
			ds1.Tables[0].Columns.Add("capngay");
			ds1.Tables[0].Columns.Add("noicap");
			ds1.Tables[0].Columns.Add("noidung");
			ds1.Tables[0].Columns.Add("sotien",typeof(decimal));
			ds1.Tables[0].Columns.Add("tongtien",typeof(decimal));
			ds1.Tables[0].Columns.Add("bangchu");
			ds1.Tables[0].Columns.Add("ketoantruong");
			ds1.Tables[0].Columns.Add("giamdoc");
			ds1.Tables[0].Columns.Add("tendv");
			ds1.Tables[0].Columns.Add("diachdv");
			ds1.Tables[0].Columns.Add("stk");
			ds1.Tables[0].Columns.Add("madvqhns");
			ds1.Tables[0].Columns.Add("mact");
			ds1.Tables[0].Columns.Add("stk_dmdt");
			ds1.Tables[0].Columns.Add("nganhang_dt");
			ds.Tables[0].Columns.Add("manns");
			ds.Tables[0].Columns.Add("tennns");
			ds.Tables[0].Columns.Add("mada");
			ds.Tables[0].Columns.Add("tenda");
			ds1.Clear();
			DataRow r1;
			foreach(DataRow r in get_data(sql).Tables[0].Rows)
			{
				so=r["soctg"].ToString();
				ngay=r["ngayg"].ToString();
				stkno=r["stkno"].ToString();
				tai=r["tennh"].ToString();
				hoten=r["hoten"].ToString();
				diachi=r["diachi"].ToString();
				noidung=r["noidung"].ToString();
				stien+=long.Parse(r["stien"].ToString());
				socmnd=r["socmnd"].ToString();
				noicap=r["noicap"].ToString();
				capngay=r["capngay"].ToString();
				madvqhns=r["madvqhns"].ToString();
				mact=r["mact"].ToString();
				nguonkp=r["nguonkp"].ToString();
				machuong=r["machuong"].ToString();
				chuong=r["chuong"].ToString();
				lctug=int.Parse(r["lctug"].ToString());
				nghiepvu=int.Parse(r["nghiepvu"].ToString());
				lk=r["lk"].ToString();
				mtmno=r["mtmno"].ToString();
				mtmco=r["mtmco"].ToString();
				stk_dmdt = r["stk_dmdt"].ToString();
				nganhang_dt=r["nganhang_dt"].ToString();
				manns=r["manns"].ToString();
				tennns=r["tennns"].ToString();
				mada=r["mada"].ToString();
				tenda=r["tenda"].ToString();
				r1=ds1.Tables[0].NewRow();
				r1["machuong"]=machuong;
				r1["nguonkp"]=nguonkp;
				r1["chuong"]=chuong;
				r1["lk"]=lk;
				r1["mtmno"]=mtmno;
				r1["mtmco"]=mtmco;
				r1["lctug"]=lctug;
				r1["nghiepvu"]=nghiepvu;
				r1["diachibv"]=Diachi;
				r1["madvqhnsbv"]=Madvqhns;
				r1["mact"]=mact;
				r1["sotug"]=so;
				r1["ngayg"]=ngay;
				r1["stkno"]=Sotk(stkno);
				r1["tentkno"]=Tenbv;
				r1["tai"]=tai;
				r1["hoten"]=hoten;
				r1["diachi"]=diachi;
				r1["socmnd"]=socmnd;
				r1["capngay"]=capngay;
				r1["noicap"]=noicap;
				r1["noidung"]=noidung;
				r1["sotien"]=r["stien"].ToString();
				r1["tongtien"]=stien;
				r1["bangchu"]=doiso.Doiso_Unicode(stien.ToString("#################"))+".";
				r1["ketoantruong"]=ketoantruong();
				r1["giamdoc"]=giamdoc();
				r1["tendv"]=Tenbv;
				r1["diachdv"]=Diachi;
				r1["stk"]=stkno;
				r1["madvqhns"]=madvqhns;
				r1["stk_dmdt"]= stk_dmdt;
				r1["nganhang_dt"]=nganhang_dt;
				r1["manns"]=manns;
				r1["tennns"]=tennns;
				r1["mada"]=mada;
				r1["tenda"]=tenda;
				ds1.Tables[0].Rows.Add(r1);
			}
			ds1.WriteXml("d:\\phieulinh.xml",XmlWriteMode.WriteSchema);
			return ds1;	
	
		}
				
		public DataSet lenhchi(string mmyy,long id)
		{
			doiso.Doisototext doiso=new doiso.Doisototext();
			string usr=user;
			string sql="select a.mact,a.soctg,to_char(a.ngayg,'dd/mm/yyyy') as ngayg,";
			sql+="case when s.account is null then t.account else s.account end as stkno,";
			sql+="case when s.tennh is null then t.tennh else s.tennh end as taino,";
			sql+="case when c.id is null then d.tendt else c.tendt end as hoten,";
			sql+="case when c.id is null then d.diachi else c.diachi end as diachi,";
			sql+="d.sotaikhoan as stkco,d.nganhang as taico,d.daidien,";
			sql+="a.noidung,b.stien,d.madvqhns,a.lctug,a.nghiepvu,x.ma as machuong,x.ten as chuong,y.lk,z.stk as mtmno,w.stk as mtmco";
			sql+=" from "+usr+".a_ct"+mmyy.Substring(2)+" a inner join "+usr+".a_ctct"+mmyy.Substring(2)+" b on a.id=b.idct ";
			sql+=" left join "+usr+".a_ctk"+mmyy.Substring(2)+" c on a.id=c.id ";
			sql+=" left join "+usr+".a_dmdt d on a.madt=d.id ";
			sql+=" inner join "+usr+".a_bcnghang e on a.lctug=e.id ";
			sql+=" left join "+usr+".a_dmnh s on a.tknoa=s.stk ";
			sql+=" left join "+usr+".a_dmnh t on a.tkcoa=t.stk ";
			sql+=" left join "+usr+".a_dmchuong x on a.chuong=x.id ";
			sql+=" left join "+usr+".a_dmlk y on b.lk=y.id ";
			sql+=" left join "+usr+".a_dmch z on b.mtmno=z.id ";
			sql+=" left join "+usr+".a_dmch w on b.mtmco=w.id ";
			sql+=" where a.id="+id+" order by b.stt";
			string so="",ngay="",stkno="",taino="",hoten="",stkco="",taico="",noidung="",diachi="",daidien="",madvqhns="",mact="";
			string machuong="",chuong="",lk="",mtmno="",mtmco="";
			int lctug=0,nghiepvu=0;
			long stien=0;
			foreach(DataRow r in get_data(sql).Tables[0].Rows)
			{
				so=r["soctg"].ToString();
				ngay=r["ngayg"].ToString();
				stkno=r["stkno"].ToString();
				taino=r["taino"].ToString();
				hoten=r["hoten"].ToString();
				noidung=r["noidung"].ToString();
				stien+=long.Parse(r["stien"].ToString());
				stkco=r["stkco"].ToString();
				taico=r["taico"].ToString();
				madvqhns=r["madvqhns"].ToString();
				mact=r["mact"].ToString();
				machuong=r["machuong"].ToString();
				chuong=r["chuong"].ToString();
				lctug=int.Parse(r["lctug"].ToString());
				nghiepvu=int.Parse(r["nghiepvu"].ToString());
				lk=r["lk"].ToString();
				mtmno=r["mtmno"].ToString();
				mtmco=r["mtmco"].ToString();
				diachi=r["diachi"].ToString();
			}
			DataSet ds1=new DataSet();
			ds1=get_data("select 0 as id from dual");
			ds1.Tables[0].Columns.Add("lctug",typeof(decimal));
			ds1.Tables[0].Columns.Add("nghiepvu",typeof(decimal));
			ds1.Tables[0].Columns.Add("machuong");
			ds1.Tables[0].Columns.Add("chuong");
			ds1.Tables[0].Columns.Add("lk");
			ds1.Tables[0].Columns.Add("mtmno");
			ds1.Tables[0].Columns.Add("mtmco");
			ds1.Tables[0].Columns.Add("diachibv");
			ds1.Tables[0].Columns.Add("madvqhnsbv");
			ds1.Tables[0].Columns.Add("sotug");
			ds1.Tables[0].Columns.Add("ngayg");
			ds1.Tables[0].Columns.Add("tentkno");
			ds1.Tables[0].Columns.Add("stkno");
			ds1.Tables[0].Columns.Add("taino");
			ds1.Tables[0].Columns.Add("sotien",typeof(decimal));
			ds1.Tables[0].Columns.Add("bangchu");
			ds1.Tables[0].Columns.Add("tentkco");
			ds1.Tables[0].Columns.Add("stkco");
			ds1.Tables[0].Columns.Add("taico");
			ds1.Tables[0].Columns.Add("diachi");
			ds1.Tables[0].Columns.Add("daidien");
			ds1.Tables[0].Columns.Add("noidung");
			ds1.Tables[0].Columns.Add("ketoantruong");
			ds1.Tables[0].Columns.Add("giamdoc");
			ds1.Tables[0].Columns.Add("madvqhns");
			ds1.Tables[0].Columns.Add("mact");
			DataRow [] r1=ds1.Tables[0].Select("id=0");
			r1[0]["machuong"]=machuong;
			r1[0]["chuong"]=chuong;
			r1[0]["lk"]=lk;
			r1[0]["mtmno"]=mtmno;
			r1[0]["mtmco"]=mtmco;
			r1[0]["lctug"]=lctug;
			r1[0]["nghiepvu"]=nghiepvu;
			r1[0]["sotug"]=so;
			r1[0]["ngayg"]=ngay;
			r1[0]["tentkno"]=Tenbv;
			r1[0]["diachibv"]=Diachi;
			r1[0]["madvqhnsbv"]=Madvqhns;
			r1[0]["stkno"]=Sotk(stkno);
			r1[0]["taino"]=taino;
			r1[0]["sotien"]=stien;
			r1[0]["bangchu"]=doiso.Doiso_Unicode(stien.ToString("#################"))+" đồng.";
			r1[0]["tentkco"]=hoten;
			r1[0]["stkco"]=Sotk(stkco);
			r1[0]["taico"]=taico;
			r1[0]["diachi"]=diachi;
			r1[0]["daidien"]=daidien;
			r1[0]["noidung"]=noidung;
			r1[0]["ketoantruong"]=ketoantruong();
			r1[0]["giamdoc"]=giamdoc();
			r1[0]["madvqhns"]=madvqhns;
			r1[0]["mact"]=mact;
			ds1.AcceptChanges();
			return ds1;		
		}

		public bool bAutoupdate
		{
			get
			{
				try
				{
					DataSet ds=get_data("select ten from thongso where id=422");
					return int.Parse(ds.Tables[0].Rows[0][0].ToString())==1;
				}
				catch{return false;}
			}
		}

		public string Path_medisoft
		{
			get
			{
				try
				{
					DataSet ds=get_data("select ten from thongso where id=423");
					return ds.Tables[0].Rows[0][0].ToString();
				}
				catch{return "";}
			}
		}

		public int d_thanhtien_le(int d_nhom)
		{
			ds=get_data("select ten from d_thongso where id=59 and nhom="+d_nhom);
			if (ds.Tables[0].Rows.Count==0) return 2;
			return int.Parse(ds.Tables[0].Rows[0][0].ToString());
		}

		public string format_sotien(int d_nhom)
		{
			string ret="###,###,###,##0";
			int n=(d_nhom==0)?2:d_thanhtien_le(d_nhom);
			if (n>0) ret+=".";
			for(int i=0;i<n;i++) ret+="0";
			return ret;
		}

		public void close()
		{
			if (con!=null)
			{
				con.Close();con.Dispose();
			}
		}

		public bool bdMmyy(string mmyy)
		{
			return get_data("select * from d_table where mmyy='"+mmyy+"'").Tables[0].Rows.Count>0;
		}

		public int iNgaykiemke
		{
			get
			{
				ds=get_data("select ten from d_thongso where id=105");
				if (ds.Tables[0].Rows.Count>0) return int.Parse(ds.Tables[0].Rows[0]["ten"].ToString());
				else return 7;
			}
		}

		public bool upd_thanhtoan(string mmyy,long id,decimal sotien)
		{
			string xxx=user+"d"+mmyy;
			sql="update "+xxx+".d_thanhtoan set sotien=sotien+:sotien where id=:id";
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("sotien",OracleType.Number).Value=sotien;
				cmd.Parameters.Add("id",OracleType.Number).Value=id;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+xxx+".d_thanhtoan(id,sotien,datra) values (:id,:sotien,0)";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("id",OracleType.Number).Value=id;
					cmd.Parameters.Add("sotien",OracleType.Number).Value=sotien;
					irec=cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(OracleException ex)
			{
				upd_error(ex.Message,sComputer,"d_thanhtoan");
				return false;
			}
			finally
			{
				cmd.Dispose();
				con.Close();con.Dispose();
			}		
			return true;
		}

		public void updrec_congno(DataTable dt,string mmyy,long id,string sophieu,string ngaysp,string sohd,string ngayhd,
			string madv,string no,string co,decimal sotien,decimal datra,string kho,long macongno,long stkkho,int tcnkp,
			int userid,string nguon)
		{
			string exp="id="+id;
			DataRow r = getrowbyid (dt,exp); 
			if ( r == null )
			{
				DataRow nrow = dt.NewRow ( ) ;
				nrow["mmyy"]=mmyy;
				nrow["id"] = id;
				nrow["sophieu"] = sophieu;
				nrow["ngaysp"] = ngaysp;
				nrow["sohd"] = sohd;
				nrow["ngayhd"] = ngayhd;
				nrow["madv"]=madv;
				nrow["no"] = no;
				nrow["co"] = co;
				nrow["sotien"] = sotien;
				nrow["datra"] = datra;
				nrow["chon"]=datra!=0;
				nrow["kho"]=kho;
				nrow["macongno"]=macongno;
				nrow["stkkho"]=stkkho;
				nrow["tcnkp"]=tcnkp;
				nrow["userid"]=userid;
				nrow["nguon"]=nguon;
				dt.Rows.Add ( nrow ) ;
			}
		}
		public void updrec (DataTable dt,int id,string userid,string password,string hoten,string right)
		{
			string exp="id="+id;
			DataRow r = getrowbyid (dt,exp); 
			if ( r == null )
			{
				DataRow nrow = dt.NewRow ( ) ;
				nrow[0] = id;
				nrow[2] = userid;
				nrow[3] = password;
				nrow[4] = right;
				nrow[1] = hoten;
				dt.Rows.Add ( nrow ) ;
			}
			else
			{
				DataRow[] dr = dt.Select(exp);
				dr[0][4] = right;
			}
		}
		public bool upd_a_dlogin(int m_id,string m_right)
		{
			sql = "update " + user + ".a_dlogin set right_=:m_right where id=:m_id";
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd = new OracleCommand(sql, con);
				cmd.CommandType = CommandType.Text;
				cmd.Parameters.Add("m_right", OracleType.VarChar,4000).Value = m_right;
				cmd.Parameters.Add("m_id", OracleType.Number).Value = m_id;
				cmd.ExecuteNonQuery();
				cmd.Dispose();
			}
			catch(OracleException ex)
			{
				upd_error(ex.Message,sComputer,"a_dlogin");
				return false;
			}
			finally
			{
				
				con.Close();con.Dispose();
			}		
			return true;
		}
		public bool upd_a_menuitem(string id, string id_menu, string id_goc, decimal stt, string ten)
		{
			sql = "update " + user + ".a_menuitem set id_menu=:id_menu,id_goc=:id_goc, stt=:stt,ten=:ten where id=:id ";
			con = new OracleConnection(sConn);
			try
			{
				try
				{
					con.Open();
					cmd = new OracleCommand(sql, con);
					cmd.CommandType = CommandType.Text;
					cmd.Parameters.Add("id", OracleType.VarChar,5).Value = id;
					cmd.Parameters.Add("id_menu", OracleType.VarChar,5).Value = id_menu;
					cmd.Parameters.Add("id_goc", OracleType.VarChar,5).Value = id_goc;
					cmd.Parameters.Add("stt", OracleType.Number).Value = stt;
					cmd.Parameters.Add("ten", OracleType.NVarChar,500).Value = ten;
					int num = cmd.ExecuteNonQuery();
					cmd.Dispose();
					if (num == 0)
					{
						sql = "insert into " + user + ".a_menuitem(id,id_menu,id_goc,stt,ten) values (:id,:id_menu,:id_goc,:stt,:ten)";
						cmd = new OracleCommand(sql, con);
						cmd.CommandType = CommandType.Text;
						cmd.Parameters.Add("id", OracleType.VarChar,5).Value = id;
						cmd.Parameters.Add("id_menu", OracleType.VarChar,5).Value = id_menu;
						cmd.Parameters.Add("id_goc", OracleType.VarChar,5).Value = id_goc;
						cmd.Parameters.Add("stt", OracleType.Number).Value = stt;
						cmd.Parameters.Add("ten", OracleType.NVarChar,500).Value = ten;
						num = cmd.ExecuteNonQuery();
						cmd.Dispose();
					}
				}
				catch (OracleException exception)
				{
					upd_error(exception.Message, sComputer, "m_menuitem");
					return false;
				}
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public int iHoatdong() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=700").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}

		public int iLctug() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=701").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}
		public int iChuong() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=702").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}
		public int iNghiepvu() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=703").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}
		public int iLoaibk() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=705").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}
		public int iLk() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=706").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}
		
		public int iCapphat() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=707").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}

		public string sNoidung() 
		{
			try
			{
				return get_data("select ten from a_thongso where id=708").Tables[0].Rows[0]["ten"].ToString().Trim();
			}
			catch{return "";}
		}

		public int iUserid() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=709").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}

		public int iNhom() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=710").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}

		public bool bStkhangnam() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=711").Tables[0].Rows[0]["ten"].ToString().Trim())==1;
			}
			catch{return false;}
		}

		public int iKhoanmucno() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=712").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}


		public int iHoatdongv() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=900").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}

		public int iLctugv() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=901").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}
		public int iChuongv() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=902").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}
		public int iNghiepvuv() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=903").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}
		public int iTcnkpv() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=904").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}
		public int iLoaibkv() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=905").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}
		public int iLkv() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=906").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}
		
		public int iCapphatv() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=907").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}

		public string sNoidungv() 
		{
			try
			{
				return get_data("select ten from a_thongso where id=908").Tables[0].Rows[0]["ten"].ToString().Trim();
			}
			catch{return "";}
		}

		public int iUseridv() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=909").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}

		public int iNhomv() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=910").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}

		public int iKhoanmucnov() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=912").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}

		public int iHoatdongx() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=800").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}

		public int iLctugx() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=801").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}
		public int iChuongx() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=802").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}
		public int iNghiepvux() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=803").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}
		public int iLoaibkx() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=805").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}
		public int iLkx() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=806").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}
		
		public int iCapphatx() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=807").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}

		public string sNoidungx() 
		{
			try
			{
				return get_data("select ten from a_thongso where id=808").Tables[0].Rows[0]["ten"].ToString().Trim();
			}
			catch{return "";}
		}

		public int iUseridx() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=809").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}

		public int iNhomx() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=810").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}

		public int iKhoanmucnox() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=812").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}

		public bool bStkhangnamx() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=811").Tables[0].Rows[0]["ten"].ToString().Trim())==1;
			}
			catch{return false;}
		}

		public int iTknonamtruoc() 
		{
			try
			{
				return int.Parse(get_data("select ten from a_thongso where id=813").Tables[0].Rows[0]["ten"].ToString().Trim());
			}
			catch{return 0;}
		}


		public bool upd_dmnhombc(long id,decimal stt,string ma,string ten,int userid)
		{
			string table=user+".a_dmnhombc";
			sql="update "+table+" set stt="+stt+",ma=:ma,ten=:ten,userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try 
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ma", OracleType.VarChar,3).Value = ma;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="INSERT INTO "+table+" (id,stt,ma,ten,userid) values ("+id+","+stt+",:ma,:ten,"+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ma", OracleType.VarChar,3).Value = ma;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					irec=cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			} 
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool updCtgs(string mmyy,long id,int idbc,int chuong,int lk,string ctgs,string ngaygs,string noidung,
			decimal stien,int lctug,int chucnang,int userid)
		{
			string table=user+".a_ctgs"+mmyy.Substring(2);
			sql="update "+table+" set idbc="+idbc+",chuong="+chuong+",lk="+lk+",ctgs='"+ctgs+"',ngaygs=to_date('"+ngaygs+"','dd/mm/yyyy')";
			sql+=",noidung=:noidung,stien="+stien+",thanggs='"+mmyy.Substring(0,2)+"',lctug="+lctug+",chucnang="+chucnang;
			sql+=",userid="+userid+" where id="+id;
			con=new OracleConnection(sConn);
			try 
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("noidung", OracleType.NVarChar,254).Value = noidung;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="INSERT INTO "+table+" (id,idbc,chuong,lk,ctgs,ngaygs,noidung,stien,thanggs,lctug,chucnang,userid)";
					sql+=" VALUES("+id+","+idbc+","+chuong+","+lk+",'"+ctgs+"',to_date('"+ngaygs+"','dd/mm/yyyy'),:noidung,"+stien+",'"+mmyy.Substring(0,2)+"',"+lctug+","+chucnang+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("noidung", OracleType.NVarChar,254).Value = noidung;
					irec=cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			} 
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool upd_dmmaubc(long id,decimal tt,string maubieu,string ten,decimal socot,int userid)
		{
			string table=user+".a_dmmaubc";
			sql="update "+table+" set tt="+tt+",maubieu='"+maubieu+"',ten=:ten,socot="+socot+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try 
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="INSERT INTO "+table+" (id,tt,maubieu,ten,socot,userid)";
					sql+=" VALUES("+id+","+tt+",'"+maubieu+"',:ten,"+socot+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ten", OracleType.NVarChar,254).Value = ten;
					irec=cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			} 
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool upd_maubc(long id,long idm,decimal tt,string stt,string ct,string maso,
			string tminh,string ghichu,string indam,string matg,int tinhtg,decimal dau,string mcode,int bc,int userid)
		{
			string table=user+".a_maubc";
			sql="update "+table+" set idm="+idm+",tt="+tt+",stt='"+stt+"',ct=:ct,maso='"+maso+"',";
			sql+="tminh=:tminh,ghichu=:ghichu,indam='"+indam+"',matg='"+matg+"',tinhtg="+tinhtg+",dau="+dau+",";
			sql+="mcode='"+mcode+"',bc="+bc+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try 
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ct", OracleType.NVarChar,254).Value = ct;
				cmd.Parameters.Add("tminh", OracleType.NVarChar,254).Value = tminh;
				cmd.Parameters.Add("ghichu", OracleType.NVarChar,254).Value = ghichu;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="INSERT INTO "+table+" (id,idm,tt,stt,ct,maso,tminh,ghichu,indam,matg,tinhtg,dau,mcode,bc,userid)";
					sql+=" VALUES("+id+","+idm+","+tt+",'"+stt+"',:ct,'"+maso+"',:tminh,:ghichu,'"+indam+"','"+matg+"',"+tinhtg+","+dau+",'"+mcode+"',"+bc+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ct", OracleType.NVarChar,254).Value = ct;
					cmd.Parameters.Add("tminh", OracleType.NVarChar,254).Value = tminh;
					cmd.Parameters.Add("ghichu", OracleType.NVarChar,254).Value = ghichu;
					irec=cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			} 
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool upd_congthuc(long id,long idbc,decimal tt,string maso,string nguondl,decimal dau,string fielddl,
			string cthuc,decimal tencot,string stk,string mtmuc,string kmuc,string lk,string nghiepvu,string hoatdong,
			string tkno,string mtmno,string kmno,string tkco,string mtmco,string kmco,int userid)
		{
			string table=user+".a_congthuc";
			sql="update "+table+" set idbc="+idbc+",tt="+tt+",maso='"+maso+"',nguondl='"+nguondl+"',dau="+dau+",";
			sql+="fielddl='"+fielddl+"',cthuc='"+cthuc+"',tencot="+tencot+",stk='"+stk+"',mtmuc='"+mtmuc+"',";
			sql+="kmuc='"+kmuc+"',lk='"+lk+"',nghiepvu='"+nghiepvu+"',hoatdong='"+hoatdong+"',";
			sql+="tkno='"+tkno+"',mtmno='"+mtmno+"',kmno='"+kmno+"',tkco='"+tkco+"',mtmco='"+mtmco+"',";
			sql+="kmco='"+kmco+"',userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try 
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="INSERT INTO "+table+" (id,idbc,tt,maso,nguondl,dau,fielddl,cthuc,tencot,stk,mtmuc,kmuc,lk,nghiepvu,hoatdong,";
					sql+="tkno,mtmno,kmno,tkco,mtmco,kmco,userid)";
					sql+=" VALUES("+id+","+idbc+","+tt+",'"+maso+"','"+nguondl+"',"+dau+",'"+fielddl+"','"+cthuc+"',"+tencot+",'"+stk+"','"+mtmuc+"','"+kmuc+"','"+lk+"','"+nghiepvu+"','"+hoatdong+"'";
					sql+=",'"+tkno+"','"+mtmno+"','"+kmno+"','"+tkco+"','"+mtmco+"','"+kmco+"',"+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					irec=cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			} 
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		# region Thu tuc get data

		public DataRow get_datarow(string sql)
		{		
			System.Data.DataRow drData=null;
			try
			{
				drData=get_data(sql).Tables[0].Rows[0];
			}
			catch{}	;
			return drData;
		}

		#endregion

		#region Thu tuc load danh muc va tinh so du, luy ke.
		public string kt_Tinhsodu(string s_mm,string s_yy)
		{
			string s_mmSodu="";
			int i_den=int.Parse(s_mm);
			for (int i=1;i<i_den;i++)
			{
				string s_ThangNam=i.ToString().PadLeft(2,'0')+s_yy;
				sql=  "select mmyy from "+user+".a_dtsd where mmyy in('"+s_ThangNam+"')";
				try
				{
					s_mmSodu+=get_data(sql).Tables[0].Rows[0]["mmyy"].ToString()+",";
				}
				catch{};
			}
			return s_mmSodu;
		}
		public System.Data.DataRow get_Nganhang(string s_IDtk)
		{
			System.Data.DataTable dt_Nganhang;
			sql=  "select id,stk,account,tennh from "+user+".a_dmnh"; 
			sql+=" where stk="+s_IDtk;
			try
			{
				dt_Nganhang=get_data(sql).Tables[0];
				if (dt_Nganhang!=null && dt_Nganhang.Rows.Count>0)
					return dt_Nganhang.Rows[0];
				else return null;
			}
			catch
			{
				return null;
			}
		}

		//Load danh muc chuong ke toan.
		public System.Data.DataSet get_DMChuong()
		{
			sql="select ma,ten,id from "+user+".a_dmchuong where sudung=1 order by stt";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}

		public System.Data.DataSet get_DMLoaikhoan()
		{
			sql="select lk,tlk,id from "+user+".a_dmlk order by lk";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}

		public System.Data.DataSet get_DMMuc()
		{
			sql="select trim(mtm) mtm,trim(ttk) ttk,id,trim(stk)stk,p,n,tn,cc,nhmuc from "+user+".a_dmch where sudung=1 and cd=3 order by trim(mtm),ttk";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}

		public System.Data.DataSet get_DMHoatdong()
		{
			sql="select ma,ten,id,stt from "+user+".a_hoatdong where sudung=1 order by stt";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}

		public System.Data.DataSet get_DMChucnang()
		{
			sql="select to_char(id) ma,ten,id,stt from "+user+".a_dmchucnang where sudung=1 order by stt";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}

		public System.Data.DataSet get_DMloaictu(string s_IDchucnang)
		{
			sql="select maso,ten,id,lp,tkno,tkco,stt,loai,idnh from "+user+".a_bcnghang where sudung=1 ";
			sql+=" and chucnang like "+s_IDchucnang+" order by stt";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}

		public System.Data.DataSet get_DMkhoanmuc(string s_IDloaikm)
		{
			sql="select ma,ten,id,loaikm,stt from "+user+".a_dmkhoanmuc where sudung=1";
			if (s_IDloaikm!="") sql+=" and loaikm like '"+s_IDloaikm+"'";
			sql+=" order by stt";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}

		public System.Data.DataSet get_DMNhombc()
		{
			sql="select ma,ten,id,stt from "+user+".a_dmnhombc order by stt";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}

		public System.Data.DataSet get_DMKhoaphong()
		{
			sql="select trim(makp) makp,trim(tenkp) tenkp,id id from "+user+".a_btdkp where sudung=1 order by makp";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}

		public System.Data.DataSet get_DMDoituong()
		{
			sql="select trim(mavt) madt,trim(tendt) tendt,id id,loaidt,diachi,dienthoai,email,fax,masothue,sotaikhoan,nganhang,tinhtp,daidien,dtnr,dtdd,socmnd from "+user+".a_dmdt where sudung=1 order by id";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}

//		public System.Data.DataSet get_DMTaikhoan(string s_Sotk)
//		{
//			if (s_Sotk!="")
//				sql="select stk,ttk,id,sp,hethong,congno,tinhchat,loaikm from a_dmtk where trim(stk) like '"+s_Sotk+"%' and sudung=1 order by stk";
//			else 
//				sql="select stk,ttk,id,sp,hethong,congno,tinhchat,loaikm from a_dmtk where sudung=1 order by stk";
//			try
//			{
//				ds=get_data(sql).Copy();
//				if (ds!=null && ds.Tables[0].Rows.Count>0)
//					return ds;
//				else return null;
//			}
//			catch
//			{
//				return null;
//			}
//		}

		public System.Data.DataSet get_DMTaikhoancongno(string s_IDstk)
		{
			if (s_IDstk=="")
				sql="select stk,ttk,id,sp,hethong,congno,tinhchat,loaikm from "+user+".a_dmtk where sudung=1 and congno=1 order by stk";
			else 
				sql="select stk,ttk,id,sp,hethong,congno,tinhchat,loaikm from "+user+".a_dmtk where sudung=1 and congno=1 and trim(stk) like '"+s_IDstk+"%'order by stk";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}

		public System.Data.DataSet get_DMTaikhoan_Socai()
		{
			sql="select stk,ttk,id,sp,hethong,congno,tinhchat,loaikm from "+user+".a_dmtk where sudung=1 and mlns=1 order by stk";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}

		public System.Data.DataSet get_Sodudauky_all(string s_IDchuong,string s_IDtk,string s_IDlk,string s_IDhoatdong,string s_IDnhombc,string s_yy)
		{
			sql=  "select sd.* from "+user+".a_sd"+s_yy+" sd"; 
			sql+=" where sd.stka in("+s_IDtk+")";
			if (s_IDchuong!="") sql+=" and chuong='"+s_IDchuong+"'";
			if (s_IDlk!="") sql+=" and lk='"+s_IDlk+"'";
			if (s_IDhoatdong!="") sql+=" and hoatdong='"+s_IDhoatdong+"'";
			if (s_IDnhombc!="") sql+=" and idbc='"+s_IDnhombc+"'";
			try
			{
				ds=get_data(sql).Copy();
			}
			catch{return null;};
			if(ds!=null&&ds.Tables[0].Rows.Count>0)
				return ds;
			else return null;
		}

		public decimal get_Sodudauky(string s_mm,string s_yy,string s_IDchuong,string s_IDtk,string s_IDlk,string s_IDkm,string s_IDhoatdong,string s_IDnhombc,int i_Loaiton)
		{
			//Neu i_Loaiton==1 lay sdno, neu i_Loaiton==1 lay sdco, neu i_Loaiton==3 lay sdno-sdco.
			decimal d_Sodudk=0;
			switch (i_Loaiton)
			{
				case 1:
				{
					sql=  "select sum(sd.sdno"+s_mm+") sddauky";
					sql+=" from "+user+".a_sd"+s_yy+" sd"; 
					break;
				}
				case 2:
				{
					sql=  "select sum(sd.sdco"+s_mm+") sddauky";
					sql+=" from "+user+".a_sd"+s_yy+" sd"; 
					break;
				}
				case 3:
				{
					sql=  "select sum(sd.sdno"+s_mm+" - sd.sdco"+s_mm+") sddauky";
					sql+=" from "+user+".a_sd"+s_yy+" sd"; 
					break;
				}
				default:
				{
					sql=  "select 0 sddauky";
					sql+=" from "+user+".a_sd"+s_yy+" sd"; 
					break;
				}
			}
			sql+=" where sd.stka in("+s_IDtk+")";
			if (s_IDchuong!="") sql+=" and chuong='"+s_IDchuong+"'";
			if (s_IDlk!="") sql+=" and lk='"+s_IDlk+"'";
			if (s_IDkm!="") sql+=" and khoanmuc='"+s_IDkm+"'";
			if (s_IDhoatdong!="") sql+=" and hoatdong='"+s_IDhoatdong+"'";
			if (s_IDnhombc!="") sql+=" and idbc='"+s_IDnhombc+"'";
			try
			{
				d_Sodudk=decimal.Parse(get_data(sql).Tables[0].Rows[0][0].ToString());
			}
			catch{};
			return d_Sodudk;
		}

		public decimal get_FSluykenam(string s_mm,string s_yy,string s_IDchuong,string s_IDtk,string s_IDlk,string s_IDkm,string s_IDhoatdong,string s_IDnhombc,int i_Loaitk)
		{
			//i_Loaitk=1 : lay luy ke phat sinh no, i_Loaitk=2 : lay luy ke phat sinh co.
			decimal d_FSluyke=0;
			int i_den=int.Parse(s_mm);
			for (int i=1;i<i_den;i++)
			{
				string s_Thang_i=i.ToString().PadLeft(2,'0');
				if (i_Loaitk==1) sql=  "select sum(sd.fsno"+s_Thang_i+") fsluyke";
				else sql=  "select sum(sd.fsco"+s_Thang_i+") fsluyke";
				sql+=" from "+user+".a_sd"+s_yy+" sd"; 
				sql+=" where sd.stka in("+s_IDtk+")";
				if (s_IDchuong!="") sql+=" and chuong='"+s_IDchuong+"'";
				if (s_IDlk!="") sql+=" and lk='"+s_IDlk+"'";
				if (s_IDkm!="") sql+=" and khoanmuc='"+s_IDkm+"'";
				if (s_IDhoatdong!="") sql+=" and hoatdong='"+s_IDhoatdong+"'";
				if (s_IDnhombc!="") sql+=" and idbc='"+s_IDnhombc+"'";
				try
				{
					d_FSluyke+=decimal.Parse(get_data(sql).Tables[0].Rows[0][0].ToString());
				}
				catch{};
			}
			return d_FSluyke;
		}

		public decimal get_FSluykequy(string s_mm,string s_yy,string s_IDchuong,string s_IDtk,string s_IDlk,string s_IDkm,string s_IDhoatdong,string s_IDnhombc,int i_Loaitk)
		{
			decimal d_FSluyke=0;
			int i_den=int.Parse(s_mm);
			int i_tu=((i_den-1)/3)*3+1;
			for (int i=i_tu;i<i_den;i++)
			{
				string s_Thang_i=i.ToString().PadLeft(2,'0');
				if (i_Loaitk==1) sql=  "select sum(sd.fsno"+s_Thang_i+") fsluyke";
				else sql=  "select sum(sd.fsco"+s_Thang_i+") fsluyke";
				sql+=" from "+user+".a_sd"+s_yy+" sd"; 
				sql+=" where sd.stka in("+s_IDtk+")";
				if (s_IDchuong!="") sql+=" and chuong='"+s_IDchuong+"'";
				if (s_IDlk!="") sql+=" and lk='"+s_IDlk+"'";
				if (s_IDkm!="") sql+=" and khoanmuc='"+s_IDkm+"'";
				if (s_IDhoatdong!="") sql+=" and hoatdong='"+s_IDhoatdong+"'";
				if (s_IDnhombc!="") sql+=" and idbc='"+s_IDnhombc+"'";
				try
				{
					d_FSluyke+=decimal.Parse(get_data(sql).Tables[0].Rows[0][0].ToString());
				}
				catch{};
			}
			return d_FSluyke;
		}

		public decimal get_Sodudauky_dt(string s_mm,string s_yy,string s_IDtk,string s_IDlk,string s_Madt,int i_Loaiton)
		{
			//Neu i_Loaiton==1 lay sdno, neu i_Loaiton==1 lay sdco, neu i_Loaiton==3 lay sdno-sdco.
			decimal d_Sodudk=0;
			switch (i_Loaiton)
			{
				case 1:
				{
					sql=  "select sum(sd.sdno"+s_mm+") sddauky";
					sql+=" from "+user+".a_sd"+s_yy+" sd"; 
					break;
				}
				case 2:
				{
					sql=  "select sum(sd.sdco"+s_mm+") sddauky";
					sql+=" from "+user+".a_sd"+s_yy+" sd"; 
					break;
				}
				case 3:
				{
					sql=  "select sum(sd.sdno"+s_mm+" - sd.sdco"+s_mm+") sddauky";
					sql+=" from "+user+".a_sd"+s_yy+" sd"; 
					break;
				}
				default:
				{
					sql=  "select 0 sddauky";
					sql+=" from "+user+".a_sd"+s_yy+" sd"; 
					break;
				}
			}
			sql+=" where sd.stka in("+s_IDtk+")";
			if (s_IDlk!="") sql+=" and lk='"+s_IDlk+"'";
			if (s_Madt!="") sql+=" and madt='"+s_Madt+"'";
			try
			{
				d_Sodudk=decimal.Parse(get_data(sql).Tables[0].Rows[0][0].ToString());
			}
			catch{};
			return d_Sodudk;
		}
		public decimal get_FSluykequy_dt(string s_mm,string s_yy,string s_IDtk,string s_IDlk,string s_Madt,int i_Loaitk)
		{
			decimal d_FSluyke=0;
			int i_den=int.Parse(s_mm);
			int i_tu=((i_den-1)/3)*3+1;
			for (int i=i_tu;i<i_den;i++)
			{
				string s_Thang_i=i.ToString().PadLeft(2,'0');
				if (i_Loaitk==1) sql=  "select sum(sd.fsno"+s_Thang_i+") fsluyke";
				else sql=  "select sum(sd.fsco"+s_Thang_i+") fsluyke";
				sql+=" from "+user+".a_sd"+s_yy+" sd"; 
				sql+=" where sd.stka in("+s_IDtk+")";
				if (s_IDlk!="") sql+=" and lk='"+s_IDlk+"'";
				if (s_Madt!="") sql+=" and madt='"+s_Madt+"'";
				try
				{
					d_FSluyke+=decimal.Parse(get_data(sql).Tables[0].Rows[0][0].ToString());
				}
				catch{};
			}
			return d_FSluyke;
		}
		public decimal get_FSluykenam_dt(string s_mm,string s_yy,string s_IDtk,string s_IDlk,string s_Madt,int i_Loaitk)
		{
			decimal d_FSluyke=0;
			int i_den=int.Parse(s_mm);
			for (int i=1;i<i_den;i++)
			{
				string s_Thang_i=i.ToString().PadLeft(2,'0');
				if (i_Loaitk==1) sql=  "select sum(sd.fsno"+s_Thang_i+") fsluyke";
				else sql=  "select sum(sd.fsco"+s_Thang_i+") fsluyke";
				sql+=" from "+user+".a_sd"+s_yy+" sd"; 
				sql+=" where sd.stka in("+s_IDtk+")";
				if (s_IDlk!="") sql+=" and lk='"+s_IDlk+"'";
				if (s_Madt!="") sql+=" and madt='"+s_Madt+"'";
				try
				{
					d_FSluyke+=decimal.Parse(get_data(sql).Tables[0].Rows[0][0].ToString());
				}
				catch{};
			}
			return d_FSluyke;
		}
		//Ham lay tat ca so tai khoan co phan dau giong dieu kien dua vao.
		public decimal get_FSluyke_ds(string filter,System.Data.DataSet dsFS,string field_No,string field_Co,int i_Loaitk)
		{
			decimal d_FSluyke=0;
			try
			{
				if (i_Loaitk==1) d_FSluyke=decimal.Parse(dsFS.Tables[0].Compute("sum("+field_No+")",filter).ToString());
				else d_FSluyke=decimal.Parse(dsFS.Tables[0].Compute("sum("+field_Co+")",filter).ToString());
			}
			catch{}	;
			return d_FSluyke;
		}
		public string get_ID_Stk(string s_Stk)
		{
			string s_IDtk="";
			try
			{
				if (s_Stk!="")
				{
					sql="select id from "+user+".a_dmtk where trim(stk) like '"+s_Stk+"%' order by id";
					foreach(System.Data.DataRow dr in get_data(sql).Tables[0].Rows)
					{ 
						s_IDtk+=dr["id"].ToString()+",";
					}
					if (s_IDtk.Substring(s_IDtk.Length-1,1)==",") s_IDtk=s_IDtk.Substring(0,s_IDtk.Length-1);
				}
			}
			catch{}	;
			return s_IDtk;
		}

		public string get_ID_Muc(string s_Mtm)
		{
			string s_IDmuc="";
			try
			{
				sql="select id from "+user+".a_dmch where trim(mtm) like '"+s_Mtm.Trim()+"%' order by id";
				foreach(System.Data.DataRow dr in get_data(sql).Tables[0].Rows)
				{ 
					s_IDmuc+=dr["id"].ToString()+",";
				}
			
				if (s_IDmuc.Substring(s_IDmuc.Length-1,1)==",") s_IDmuc=s_IDmuc.Substring(0,s_IDmuc.Length-1);

			}
			catch{}	;
			return s_IDmuc;
		}

		//Lay danh muc nguon ngan sach
		public string get_Nguonns(string s_Stk, System.Data.DataTable dt_Hoatdong, string s_Hoatdong)
		{
			string s_Nguonns="";
			try
			{
				if ((s_Stk.Trim().IndexOf(".")>0) && (s_Hoatdong.Trim()!=""))
				{
					string s_IDhoatdong=getrowbyid(dt_Hoatdong,"ma='"+s_Hoatdong.Trim()+"'")["id"].ToString().Trim();
					string s_Manguon=s_Stk.Trim().Split('.')[1].ToString();
					sql="select mang,ten,id from "+user+".a_dmng where sudung=1 and mang='"+s_Manguon+"' and loaikp='"+s_IDhoatdong+"' order by mang";
					s_Nguonns=get_datarow(sql)["ten"].ToString();
				}
			}
			catch{}	;
			return s_Nguonns;
		}

		#endregion
	
		public void Dispose()
		{
			con.Close();con.Dispose();
		}

		#region Thu tuc truy xuat du lieu.
		public System.Data.DataSet get_Sodudauky_all(string s_IDtk,string s_IDlk,string s_yy)
		{
			sql=  "select sd.* from a_sd"+s_yy+" sd"; 
			sql+=" where sd.stka in("+s_IDtk+")";
			if (s_IDlk!="") sql+=" and lk='"+s_IDlk+"'";
			try
			{
				ds=get_data(sql).Copy();
			}
			catch{return null;};
			if(ds!=null&&ds.Tables[0].Rows.Count>0)
				return ds;
			else return null;
		}

		public decimal get_Sodudauky(string s_mm,string s_yy,string s_IDtk,string s_IDlk,int i_Loaiton)
		{
			//Neu i_Loaiton==1 lay sdno, neu i_Loaiton==1 lay sdco, neu i_Loaiton==3 lay sdno-sdco.
			decimal d_Sodudk=0;
			switch (i_Loaiton)
			{
				case 1:
				{
					sql=  "select sum(sd.sdno"+s_mm+") sddauky";
					sql+=" from a_sd"+s_yy+" sd"; 
					break;
				}
				case 2:
				{
					sql=  "select sum(sd.sdco"+s_mm+") sddauky";
					sql+=" from a_sd"+s_yy+" sd"; 
					break;
				}
				case 3:
				{
					sql=  "select sum(sd.sdno"+s_mm+" - sd.sdco"+s_mm+") sddauky";
					sql+=" from a_sd"+s_yy+" sd"; 
					break;
				}
				default:
				{
					sql=  "select 0 sddauky";
					sql+=" from a_sd"+s_yy+" sd"; 
					break;
				}
			}
			sql+=" where sd.stka in("+s_IDtk+")";
			if (s_IDlk!="") sql+=" and lk='"+s_IDlk+"'";
			try
			{
				d_Sodudk=decimal.Parse(get_data(sql).Tables[0].Rows[0][0].ToString());
			}
			catch{};
			return d_Sodudk;
		}

		public decimal get_FSluykenam_quy(string s_yy,string s_sotk,string s_IDlk,int i_Loaitk, int CT_Quy,int i_tu, bool b_checkChuong, string idChuong, bool b_checkHoatDong, string idHoatDong, string idNhombc, bool b_checkNhombc)
		{
			decimal d_FSluyke=0;
			for (int i=CT_Quy;i<i_tu;i++)
			{
				string s_Thang_i=i.ToString().PadLeft(2,'0');
				if (i_Loaitk==1) sql=  "select sum(sd.fsno"+s_Thang_i+") fsluyke";
				else sql=  "select sum(sd.fsco"+s_Thang_i+") fsluyke";
				sql+=" from a_sd"+s_yy+" sd,a_dmtk b";
				sql+=" where sd.stka=b.id and b.stk like '"+s_sotk+"%'";
				if (s_IDlk!="") sql+=" and lk='"+s_IDlk+"'";
				if(b_checkChuong)sql+=" and sd.chuong="+idChuong;
				if(b_checkHoatDong)sql+=" and sd.hoatdong="+idHoatDong;
				if(b_checkNhombc)sql+=" and sd.idbc="+idNhombc;
				try
				{
					d_FSluyke+=decimal.Parse(get_data(sql).Tables[0].Rows[0][0].ToString());
				}
				catch{};
			}
			return d_FSluyke;
		}		
		public decimal get_FSluykenam(string s_yy,string s_IDlk,int i_Loaitk,int i_tu, bool b_checkChuong, string idChuong, bool b_checkHoatDong, string idHoatDong, string idNhombc, bool b_checkNhombc)
		{
			decimal d_FSluyke=0;
			for (int i=1;i<i_tu;i++)
			{
				string s_Thang_i=i.ToString().PadLeft(2,'0');
				if (i_Loaitk==1) sql=  "select sum(sd.fsno"+s_Thang_i+") fsluyke";
				else sql=  "select sum(sd.fsco"+s_Thang_i+") fsluyke";
				sql+=" from a_sd"+s_yy+" sd,a_dmtk b";
				sql+=" where sd.stka=b.id";
				if(idHoatDong=="1")
				{
					sql+=" and (b.stk like '46111%' or b.stk like '46121%' or b.stk like '66111%'or b.stk like '66121%')";
					sql+="	and substr(b.stk,7,2)=c.mang";
				}
				else
					if(idHoatDong=="2")
				{
					sql+=" and (b.stk like '46112%' or b.stk like '46122%' or b.stk like '66112%' or b.stk like '66122%')";
					sql+="	and substr(b.stk,7,2)=c.mang ";
				}
				else
					if(idHoatDong=="0")
					sql+=" and ((b.stk like '462%' and substr(b.stk,6,2)=c.mang) or (b.stk like '6621%' and b.stk like '6622%' and substr(b.stk,7,2))";
				if (s_IDlk!="") sql+=" and lk='"+s_IDlk+"'";
				if(b_checkChuong)sql+=" and sd.chuong="+idChuong;
				if(b_checkHoatDong)sql+=" and sd.hoatdong="+idHoatDong;
				if(b_checkNhombc)sql+=" and sd.idbc="+idNhombc;
				try
				{
					d_FSluyke+=decimal.Parse(get_data(sql).Tables[0].Rows[0][0].ToString());
				}
				catch{};
			}
			return d_FSluyke;
		}		
		public string get_FSluykenam_muc(string s_yy,int tuthang,string s_sotk,string s_IDMuc,string s_IDlk, bool b_CheckChuong, string s_IDChuong, bool b_CheckHoatDong, string s_IDHoatDong, string s_IDNhombc, bool b_CheckNhombc)
		{
			string sql="";				
			for (int i=0;i<tuthang;i++)
			{
				string s_Thang_i=i.ToString().PadLeft(2,'0');
				if(i==0)sql=" select 0 luyke_no, 0 luyke_co,";
				else
				{
					sql=  "select sum(sd.fsno"+s_Thang_i+") luyke_no,";
					sql+=  "sum(sd.fsco"+s_Thang_i+") luyke_co,";
				}
				sql+=" substr(trim(mtm),6,length(trim(mtm))) as tmtm, substr(trim(mtm),0,4) as muc,";
				sql+=" substr(trim(mtm),6,4) as tm, '' ttk";
				sql+=" from a_sd"+s_yy+" sd, a_dmch b, a_dmtk c"; 
				sql+=" where sd.mtmuc=b.id";
				sql+= " and sd.stka=c.id";
				sql+=" and c.stk like '"+s_sotk+"%'";
				if(s_IDMuc!="") sql+=" and b.mtm like '"+s_IDMuc+"%'";
				if (s_IDlk!="") sql+=" and lk='"+s_IDlk+"'";
				if(b_CheckChuong)sql+=" and sd.chuong="+s_IDChuong;
				if(b_CheckHoatDong)sql+=" and sd.hoatdong="+s_IDHoatDong;
				if(b_CheckNhombc)sql+=" and sd.idbc="+s_IDNhombc;
				sql+=" group by b.stk,mtm";				
	                			
			}				
			return sql;
		}
		public string get_SdDauKy_muc(string s_yy,string s_mm,string s_sotk,string s_IDMuc,string s_IDlk, bool b_CheckChuong, string s_IDChuong, bool b_CheckHoatDong, string s_IDHoatDong, string s_IDNhombc, bool b_CheckNhombc)
		{
			string sql="";
			sql+="select case when (b.stk in (select b.stk as muc from a_sd"+s_yy+" a,";
			sql+=" a_dmch b where a.mtmuc=b.id)) then sum(sdno"+s_mm+") else 0 end as sodu_no,";
			sql+=" case when (b.stk in (select b.stk as muc from a_sd"+s_yy+" a,";
			sql+=" a_dmch b where a.mtmuc=b.id )) then sum(sdco"+s_mm+") else 0 end as sodu_co,";
			sql+=" substr(b.mtm,0,4) as muc,'' ttk ";
			sql+=" from a_dmtk c,a_dmch b, a_sd"+s_yy+" a ";

			sql+=" where c.id=a.stka and c.stk like '"+s_sotk+"%' and a.mtmuc=b.id";
			if(s_IDMuc!="") sql+= " and b.mtm like'"+s_IDMuc+"%'";
			if (s_IDlk!="") sql+=" and a.lk="+s_IDlk;
			if(b_CheckChuong)sql+=" and a.chuong="+s_IDChuong;
			if(b_CheckHoatDong)sql+=" and a.hoatdong="+s_IDHoatDong;
			if(b_CheckNhombc)sql+=" and a.idbc="+s_IDNhombc;
			sql+=" group by b.stk, b.mtm";				
			
			return sql;
		}		
		#endregion	


		#region chi_bosung		
		public DataSet getAllData_Table(string tbname)
		{
			string sql="select * from "+tbname+"";
			DataSet ds = get_data(sql);
			//catch{return null;};
			if(ds!=null&&ds.Tables[0].Rows.Count>0)
				return ds;
			else return null;
		}		
		public System.Data.DataSet get_DMMuc_c()
		{
			sql="select stk, ttk, id from a_dmch where cd = 3 order by cd";			
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null || ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}
		#endregion	

		public decimal get_Sodudauky_muc(string s_mm,string s_yy,string s_IDtk,string s_IDlk,string s_STKMuc,int i_Loaiton)
		{
			//Neu i_Loaiton==1 lay sdno, neu i_Loaiton==1 lay sdco, neu i_Loaiton==3 lay sdno-sdco.
			decimal d_Sodudk=0;
			switch (i_Loaiton)
			{
				case 1:
				{
					sql=  "select sum(sd.sdno"+s_mm+") sddauky";
					sql+=" from "+user+".a_sd"+s_yy+" sd,"+user+".a_dmch dmch"; 
					break;
				}
				case 2:
				{
					sql=  "select sum(sd.sdco"+s_mm+") sddauky";
					sql+=" from "+user+".a_sd"+s_yy+" sd,"+user+".a_dmch dmch"; 
					break;
				}
				case 3:
				{
					sql=  "select sum(sd.sdno"+s_mm+" - sd.sdco"+s_mm+") sddauky";
					sql+=" from "+user+".a_sd"+s_yy+" sd,"+user+".a_dmch dmch"; 
					break;
				}
				default:
				{
					sql=  "select 0 sddauky";
					sql+=" from "+user+".a_sd"+s_yy+" sd,"+user+".a_dmch dmch"; 
					break;
				}
			}
			sql+=" where sd.stka in("+s_IDtk+") and sd.mtmuc=dmch.id";
			if (s_IDlk!="") sql+=" and lk='"+s_IDlk+"'";
			if (s_STKMuc!="") sql+=" and substr(trim(dmch.stk),1,3)='"+s_STKMuc+"'";
			try
			{
				d_Sodudk=decimal.Parse(get_data(sql).Tables[0].Rows[0][0].ToString());
			}
			catch{};
			return d_Sodudk;
		}

		public decimal get_FSluykequy(string s_mm,string s_yy,string s_IDtk,string s_IDlk,int i_Loaitk)
		{
			decimal d_FSluyke=0;
			int i_den=int.Parse(s_mm);
			int i_tu=((i_den-1)/3)*3+1;
			for (int i=i_tu;i<i_den;i++)
			{
				string s_Thang_i=i.ToString().PadLeft(2,'0');
				if (i_Loaitk==1) sql=  "select sum(sd.fsno"+s_Thang_i+") fsluyke";
				else sql=  "select sum(sd.fsco"+s_Thang_i+") fsluyke";
				sql+=" from "+user+".a_sd"+s_yy+" sd"; 
				sql+=" where sd.stka in("+s_IDtk+")";
				if (s_IDlk!="") sql+=" and lk='"+s_IDlk+"'";
				try
				{
					d_FSluyke+=decimal.Parse(get_data(sql).Tables[0].Rows[0][0].ToString());
				}
				catch{};
			}
			return d_FSluyke;
		}
		public decimal get_FSluykenam(string s_mm,string s_yy,string s_IDtk,string s_IDlk,int i_Loaitk)
		{
			decimal d_FSluyke=0;
			int i_den=int.Parse(s_mm);
			for (int i=1;i<i_den;i++)
			{
				string s_Thang_i=i.ToString().PadLeft(2,'0');
				if (i_Loaitk==1) sql=  "select sum(sd.fsno"+s_Thang_i+") fsluyke";
				else sql=  "select sum(sd.fsco"+s_Thang_i+") fsluyke";
				sql+=" from "+user+".a_sd"+s_yy+" sd"; 
				sql+=" where sd.stka in("+s_IDtk+")";
				if (s_IDlk!="") sql+=" and lk='"+s_IDlk+"'";
				try
				{
					d_FSluyke+=decimal.Parse(get_data(sql).Tables[0].Rows[0][0].ToString());
				}
				catch{};
			}
			return d_FSluyke;
		}
		public decimal get_Sumfield_ds(System.Data.DataSet dsFS,string field_DK1,string field_KQ1,string field_DK2,string field_KQ2,string field_sumNo,string field_sumCo,int i_Loaitk)
		{
			decimal d_FSluyke=0;
			try
			{
				foreach (System.Data.DataRow drDuyet in dsFS.Tables[0].Rows)
					if (drDuyet[field_DK1].ToString()==field_KQ1 && drDuyet[field_DK2].ToString()==field_KQ2)
					{
						if (i_Loaitk==1) d_FSluyke+=decimal.Parse(drDuyet[field_sumNo].ToString());
						else d_FSluyke+=decimal.Parse(drDuyet[field_sumCo].ToString());
					}
			}
			catch{}	;
			return d_FSluyke;
		}
		public DataSet get_data_2sql(string sql,String sql1)
		{		
			try
			{
				con=new OracleConnection(sConn);
				con.Open();
				ds=new DataSet();

				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				dest=new OracleDataAdapter(cmd);
				dest.Fill(ds,"Table");	

				OracleCommand cmd1=new OracleCommand(sql1,con);
				cmd1.CommandType=CommandType.Text;
				dest=new OracleDataAdapter(cmd1);
				dest.Fill(ds,"Table1");

				cmd1.Dispose();
				cmd.Dispose();				
				con.Dispose();
			}
			catch(OracleException ex)
			{
				cmd.Dispose();				
				con.Dispose();
				upd_error(ex.Message.ToString().Trim(),sComputer,"?");
			}
			return ds;
		}

		public bool upd_dmfieldsl(long id,string sx,int solieubc,string tenfield,string diengiai,string nguon)
		{
			string table=user+".a_dmfieldsl";
			sql="update "+table+" set sx='"+sx+"',solieubc="+solieubc+",tenfield='"+tenfield+"',diengiai=:diengiai,nguon='"+nguon+"'";
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try 
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("diengiai", OracleType.NVarChar,254).Value = diengiai;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="INSERT INTO "+table+" (id,sx,solieubc,tenfield,diengiai,nguon)";
					sql+=" VALUES("+id+",'"+sx+"',"+solieubc+",'"+tenfield+"',:diengiai,'"+nguon+"')";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("diengiai", OracleType.NVarChar,254).Value = diengiai;
					irec=cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			} 
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool upd_hachtoan(string mmyy,long id,long stk,long stkch,int loai,int userid)
		{
			string table=user+".a_hachtoan"+mmyy.Substring(2);
			sql="update "+table+" set stk="+stk+",stkch="+stkch+",loai="+loai+",userid="+userid;
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try 
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="INSERT INTO "+table+" (id,stk,stkch,loai,sudung,userid)";
					sql+=" VALUES("+id+","+stk+","+stkch+","+loai+",1,"+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					irec=cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			} 
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public int lctug_dutoanns
		{
			get
			{
				int ret=0;
				DataTable tmp=get_data("select id from "+user+".a_bcnghang where chucnang=6 and dutoanns=1").Tables[0];
				if (tmp.Rows.Count>0) ret=int.Parse(tmp.Rows[0]["id"].ToString());
				return ret;
			}
		}

		public int lctug_dutoanns_tm
		{
			get
			{
				int ret=0;
				DataTable tmp=get_data("select id from "+user+".a_bcnghang where chucnang=1 and dutoanns=1").Tables[0];
				if (tmp.Rows.Count>0) ret=int.Parse(tmp.Rows[0]["id"].ToString());
				return ret;
			}
		}


		public int lctug_dutoanns_nghang
		{
			get
			{
				int ret=0;
				DataTable tmp=get_data("select id from "+user+".a_bcnghang where chucnang=2 and dutoanns=1").Tables[0];
				if (tmp.Rows.Count>0) ret=int.Parse(tmp.Rows[0]["id"].ToString());
				return ret;
			}
		}

		public int lctug_dutoanns_tscd
		{
			get
			{
				int ret=0;
				DataTable tmp=get_data("select id from "+user+".a_bcnghang where chucnang=3 and dutoanns=1").Tables[0];
				if (tmp.Rows.Count>0) ret=int.Parse(tmp.Rows[0]["id"].ToString());
				return ret;
			}
		}

		public int lctug_dutoanns_hhoa
		{
			get
			{
				int ret=0;
				DataTable tmp=get_data("select id from "+user+".a_bcnghang where chucnang=4 and dutoanns=1").Tables[0];
				if (tmp.Rows.Count>0) ret=int.Parse(tmp.Rows[0]["id"].ToString());
				return ret;
			}
		}
		public int lctug_dutoanns_vattu
		{
			get
			{
				int ret=0;
				DataTable tmp=get_data("select id from "+user+".a_bcnghang where chucnang=5 and dutoanns=1").Tables[0];
				if (tmp.Rows.Count>0) ret=int.Parse(tmp.Rows[0]["id"].ToString());
				return ret;
			}
		}
		public bool upd_impxuat(string mmyy,long id,int loai,string sophieu,string ngay,string tablell,string tablect,
			int makhoa,int makho,int manguon,int tcnkp,long tkno,long tknosave,string ttkno)
		{
			string table=user+".a_impxuat";
			sql="update "+table+" set tkno="+tkno;
			sql+=" where mmyy='"+mmyy+"' and id="+id+" and loai="+loai+" and sophieu='"+sophieu+"'";
			sql+=" and to_char(ngay,'dd/mm/yyyy')='"+ngay+"' and tablell='"+tablell+"' and tablect='"+tablect+"'";
			sql+=" and makhoa="+makhoa+" and makho="+makho+" and manguon="+manguon+" and tcnkp="+tcnkp;
			sql+=" and tknosave="+tknosave+" and ttkno='"+ttkno+"'";
			con=new OracleConnection(sConn);
			try 
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="INSERT INTO "+table+" (mmyy,id,loai,sophieu,ngay,tablell,tablect,makhoa,makho,manguon,tcnkp,tkno,tknosave,ttkno)";
					sql+=" VALUES('"+mmyy+"',"+id+","+loai+",'"+sophieu+"',to_date('"+ngay+"','dd/mm/yyyy'),'"+tablell+"','"+tablect+"',"+makhoa+","+makho+","+manguon+","+tcnkp+","+tkno+","+tknosave+",'"+ttkno+"')";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					irec=cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			} 
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool upd_impxuatct(string mmyy,long idct,int loai,string ngay,string ma,string ttkno)
		{
			string table=user+".a_impxuatct";
			sql="update "+table+" set ttkno="+ttkno;
			sql+=" where mmyy='"+mmyy+"' and idct="+idct+" and loai="+loai+" and ngay='"+ngay+"' and ma='"+ma+"'";
			con=new OracleConnection(sConn);
			try 
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="INSERT INTO "+table+" (mmyy,idct,loai,ngay,ma,ttkno)";
					sql+=" VALUES('"+mmyy+"',"+idct+","+loai+",'"+ngay+"','"+ma+"','"+ttkno+"')";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					irec=cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			} 
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool bQuanlynguon(int d_nhom)
		{
			ds=get_data("select ten from d_thongso where id=17 and nhom="+d_nhom);
			if (ds.Tables[0].Rows.Count==0) return false;
			return ds.Tables[0].Rows[0][0].ToString()=="1";
		}

		public bool upd_bc_nhomnguon(long d_id, long d_stt, string d_ten, long d_nhom, long d_idnguon)
		{
			sql="update bc_nhomnguon set stt=:d_stt,ten=:d_ten,nhom=:d_nhom where id=:d_id and idnguon=:d_idnguon ";
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("d_stt",OracleType.Number).Value=d_stt;
				cmd.Parameters.Add("d_ten",OracleType.VarChar,254).Value=d_ten;
				cmd.Parameters.Add("d_nhom",OracleType.Number).Value=d_nhom;
				cmd.Parameters.Add("d_id",OracleType.Number).Value=d_id;
				cmd.Parameters.Add("d_idnguon",OracleType.Number).Value=d_idnguon;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into bc_nhomnguon(stt,ten,nhom,id,idnguon) values (:d_stt,:d_ten,:d_nhom,:d_id,:d_idnguon)";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("d_stt",OracleType.Number).Value=d_stt;
					cmd.Parameters.Add("d_ten",OracleType.VarChar,254).Value=d_ten;
					cmd.Parameters.Add("d_nhom",OracleType.Number).Value=d_nhom;
					cmd.Parameters.Add("d_id",OracleType.Number).Value=d_id;
					cmd.Parameters.Add("d_idnguon",OracleType.Number).Value=d_idnguon;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(OracleException ex)
			{
				upd_error(ex.Message,sComputer,"bc_nhomnguon");
				return false;
			}
			finally
			{
				cmd.Dispose();
				con.Close();
			}
			return true;
		}

		#region huuloc
		
		public decimal getSoTien(string  sql)
		{
			decimal st =0;			
			con=new OracleConnection(sConn);
			con.Open();
			cmd=new OracleCommand(sql,con);
			cmd.CommandType=CommandType.Text;

			st = Convert.ToDecimal(cmd.ExecuteScalar());
			cmd.Dispose();
			con.Close();con.Dispose();
			return st;
		}
		
		public DataSet get_DMDuToan()
		{
			sql="select stk, ttk,id from "+user+".a_dmtk where stk like'008%' or stk like '009%' ";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}

		public DataSet get_DMNhomMuc()
		{
			sql="SELECT nhom,tennhom,id,muc FROM "+user+".a_dmnhom ORDER BY nhom";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}

		public DataSet get_DMKM()
		{
			sql="SELECT ma,loaikm,id FROM "+user+".a_dmkhoanmuc ORDER BY id";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}
	
		public DataSet get_DMCH()
		{
			sql="SELECT mtm,id FROM "+user+".a_dmch ORDER BY id";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}

		public string get_ID_Lk(string s_Lk)
		{
			string s_IDLk="";
			try
			{
				if (s_Lk!="")
				{
					sql="select id from "+user+".a_dmlk where trim(loaikm) like '"+s_Lk+"%' order by id";
					foreach(System.Data.DataRow dr in get_data(sql).Tables[0].Rows)
					{ 
						s_IDLk+=dr["id"].ToString()+",";
					}
					if (s_IDLk.Substring(s_IDLk.Length-1,1)==",") s_IDLk=s_IDLk.Substring(0,s_IDLk.Length-1);
				}
			}
			catch{}	;
			return s_IDLk;
		}
		public System.Data.DataSet get_DLogin(string hoten)
		{
			sql="select hoten,userid,password_,id ";
			sql += "from "+user+".a_dlogin where hoten ='"+ hoten + "' order by id";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}

		public DataSet get_NhatKyThuChi()
		{
			sql="select stk, ttk,id from "+user+".a_dmtk where stk like '111%' or stk like '112%' order by stk ";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}


		#endregion 	
		#region camchi 270309	
		//tinh so du dau ky
		public DataSet get_dsSodudauky(string s_mm,string s_mm1,string s_yy,string s_IDchuong,string s_IDtk,string s_IDlk,string s_IDkm,string s_IDhoatdong,string s_IDnhombc,string s_IDdoituong, string s_IDmuc,string s_IDkm2,string s_IDkm3,string s_IDkm4,int i_dkgroup)
		{
			int tuthang = int.Parse(s_mm);
			int denthang = int.Parse(s_mm1);
			string s_DKSelectgroup="",s_DKGroupbygroup="";
			string sql="";
			string s_DKgroup="", s_DKwhere="";
			string s_DKfrom="";
			if(i_dkgroup!=-1) s_DKgroup=", "+i_dkgroup+" as nhom";
			else s_DKgroup=", -1 as nhom ";	
			switch(i_dkgroup)
			{
				case 0:
					s_DKSelectgroup=" sd.chuong as idchuong, ch.ten as chuong,";
					s_DKGroupbygroup=" group by sd.chuong, ch.ten";
					s_DKfrom=" , "+user+".a_dmchuong ch";
					s_DKwhere=" and sd.chuong=ch.id";
					break;
				case 1:
					s_DKSelectgroup=" sd.madt as iddoituong, dt.tendt as doituong,";
					s_DKGroupbygroup=" group by sd.madt,dt.tendt";
					s_DKfrom=" , "+user+".a_dmdt dt";
					s_DKwhere=" and sd.madt=dt.id";
					break;
				case 2:
					s_DKSelectgroup=" sd.hoatdong as idhoatdong, hd.ten as hoatdong,";
					s_DKGroupbygroup=" group by sd.hoatdong,hd.ten";
					s_DKfrom=" , "+user+".a_hoatdong hd";
					s_DKwhere=" and sd.hoatdong=hd.id";
					break;
				case 3:
					s_DKSelectgroup=" sd.mtmuc as idmuc, ch.ttk as muc,";
					s_DKGroupbygroup=" group by sd.mtmuc,ch.ttk";
					s_DKfrom=" , "+user+".a_dmch ch";
					s_DKwhere=" and sd.mtmuc=ch.id";
					break;
				case 4:
					s_DKSelectgroup=" sd.idbc as idnhombc, bc.ten as nhombc, ";
					s_DKGroupbygroup=" group by sd.idbc,bc.ten";
					s_DKfrom=" , "+user+".a_dmnhombc bc";
					s_DKwhere=" and sd.idbc=bc.id";
					break;
				case 5:
					s_DKSelectgroup=" sd.khoanmuc as idkm, km.ten as km,";
					s_DKGroupbygroup=" group by sd.khoanmuc,km.ten";
					s_DKfrom=" , "+user+".a_dmkhoanmuc km";
					s_DKwhere=" and sd.khoanmuc=km.id";
					break;
				case 6:
					s_DKSelectgroup=" sd.khoanmuc2 as idkm2, km.ten as km2,";
					s_DKGroupbygroup=" group by sd.khoanmuc2,km.ten";
					s_DKfrom=" , "+user+".a_dmkhoanmuc km";
					s_DKwhere=" and sd.khoanmuc2=km.id";
					break;
				case 7:
					s_DKSelectgroup=" sd.khoanmuc3 as idkm3, km.ten as km3,";
					s_DKGroupbygroup=" group by sd.khoanmuc3,km.ten";
					s_DKfrom=" , "+user+".a_dmkhoanmuc km";
					s_DKwhere=" and sd.khoanmuc3=km.id";
					break;
				case 8:
					s_DKSelectgroup=" sd.khoanmuc4 as idkm4, km.ten as km4,";
					s_DKGroupbygroup=" group by sd.khoanmuc4,km.ten";
					s_DKfrom=" , "+user+".a_dmkhoanmuc km";
					s_DKwhere=" and sd.khoanmuc4=km.id";
					break;
				default: 
					s_DKSelectgroup="";
					s_DKGroupbygroup=" group by sd.stka";
					break;
			}
			for(int i = tuthang; i<= denthang ;i++ )
			{				
				sql+=" (select "+s_DKSelectgroup+" sum(sdco"+i.ToString().PadLeft(2,'0')+") as sodu_co,";
				sql+=" sum(sdno"+i.ToString().PadLeft(2,'0')+") as sodu_no,";
				sql+="'"+i.ToString().PadLeft(2,'0')+"' as thang,0 as no,0 as co";
				sql+=" "+s_DKgroup+"";
				sql+=" from "+user+".a_sd"+s_yy+" sd "+s_DKfrom+"";
				sql+=" where sd.stka in ("+s_IDtk+")";
				if(s_IDlk!="")sql+=" and sd.lk="+s_IDlk;
				if(s_IDchuong!="")sql+=" and sd.chuong="+s_IDchuong;
				if(s_IDhoatdong!="")sql+=" and sd.hoatdong="+s_IDhoatdong;
				if(s_IDnhombc!="")sql+=" and sd.idbc="+s_IDnhombc;
				if(s_IDdoituong!="")sql+=" and sd.madt='"+s_IDdoituong+"'";
				if(s_IDmuc!="")sql+=" and sd.mtmuc='"+s_IDmuc+"'";
				if (s_IDkm!="") sql+=" and sd.khoanmuc = '"+s_IDkm+"'";		
				if (s_IDkm2!="") sql+=" and sd.khoanmuc2 = '"+s_IDkm2+"'";			
				if (s_IDkm3!="") sql+=" and sd.khoanmuc3 = '"+s_IDkm3+"'";			
				if (s_IDkm4!="") sql+=" and sd.khoanmuc4 = '"+s_IDkm4+"'";
				sql+=" "+s_DKwhere+"";
				sql+=""+s_DKGroupbygroup+"";
				if(i<denthang)
					sql+=") union ";
				else
					sql+=")";
				
			}
            
			ds=get_data(sql);			
			//catch{return null;};
			if(ds!=null && ds.Tables[0].Rows.Count>0)
				return ds;
			else return null;

		}
		public DataSet get_dsSodudauky(string s_mm,string s_yy,string s_IDchuong,string s_IDtk,string s_IDlk,string s_IDkm,string s_IDhoatdong,string s_IDnhombc,string s_IDdoituong, string s_IDmuc,string s_IDkm2,string s_IDkm3,string s_IDkm4,int i_dkgroup)
		{
			int tuthang = int.Parse(s_mm);
			string s_DKSelectgroup="",s_DKGroupbygroup="";
			string sql="";
			string s_DKgroup="", s_DKwhere="";
			string s_DKfrom="";
			if(i_dkgroup!=-1) s_DKgroup=", "+i_dkgroup+" as nhom";
			else s_DKgroup=", -1 as nhom ";	
			switch(i_dkgroup)
			{
				case 0:
					s_DKSelectgroup=" sd.chuong as idchuong, ch.ten as chuong,";
					s_DKGroupbygroup=" group by sd.chuong, ch.ten";
					s_DKfrom=" , "+user+".a_dmchuong ch";
					s_DKwhere=" and sd.chuong=ch.id";
					break;
				case 1:
					s_DKSelectgroup=" sd.madt as iddoituong, dt.tendt as doituong,";
					s_DKGroupbygroup=" group by sd.madt,dt.tendt";
					s_DKfrom=" , "+user+".a_dmdt dt";
					s_DKwhere=" and sd.madt=dt.id";
					break;
				case 2:
					s_DKSelectgroup=" sd.hoatdong as idhoatdong, hd.ten as hoatdong,";
					s_DKGroupbygroup=" group by sd.hoatdong,hd.ten";
					s_DKfrom=" , "+user+".a_hoatdong hd";
					s_DKwhere=" and sd.hoatdong=hd.id";
					break;
				case 3:
					s_DKSelectgroup=" sd.mtmuc as idmuc, ch.ttk as muc,";
					s_DKGroupbygroup=" group by sd.mtmuc,ch.ttk";
					s_DKfrom=" , "+user+".a_dmch ch";
					s_DKwhere=" and sd.mtmuc=ch.id";
					break;
				case 4:
					s_DKSelectgroup=" sd.idbc as idnhombc, bc.ten as nhombc, ";
					s_DKGroupbygroup=" group by sd.idbc,bc.ten";
					s_DKfrom=" , "+user+".a_dmnhombc bc";
					s_DKwhere=" and sd.idbc=bc.id";
					break;
				case 5:
					s_DKSelectgroup=" sd.khoanmuc as idkm, km.ten as km,";
					s_DKGroupbygroup=" group by sd.khoanmuc,km.ten";
					s_DKfrom=" , "+user+".a_dmkhoanmuc km";
					s_DKwhere=" and sd.khoanmuc=km.id";
					break;
				case 6:
					s_DKSelectgroup=" sd.khoanmuc2 as idkm2, km.ten as km2,";
					s_DKGroupbygroup=" group by sd.khoanmuc2,km.ten";
					s_DKfrom=" , "+user+".a_dmkhoanmuc km";
					s_DKwhere=" and sd.khoanmuc2=km.id";
					break;
				case 7:
					s_DKSelectgroup=" sd.khoanmuc3 as idkm3, km.ten as km3,";
					s_DKGroupbygroup=" group by sd.khoanmuc3,km.ten";
					s_DKfrom=" , "+user+".a_dmkhoanmuc km";
					s_DKwhere=" and sd.khoanmuc3=km.id";
					break;
				case 8:
					s_DKSelectgroup=" sd.khoanmuc4 as idkm4, km.ten as km4,";
					s_DKGroupbygroup=" group by sd.khoanmuc4,km.ten";
					s_DKfrom=" , "+user+".a_dmkhoanmuc km";
					s_DKwhere=" and sd.khoanmuc4=km.id";
					break;
				default: 
					s_DKSelectgroup="";
					s_DKGroupbygroup=" group by sd.stka";
					break;
			}
						
			string thang=tuthang.ToString().PadLeft(2,'0');
			sql=" select "+s_DKSelectgroup+" sum(sdco"+thang+") as sodu_co,";
			sql+=" sum(sdno"+thang+") as sodu_no,";
			sql+=" 0 as sotienthu,0 as sotienchi,-2 as sapxep";
			sql+=" "+s_DKgroup+"";
			sql+=" from "+user+".a_sd"+s_yy+" sd "+s_DKfrom+"";
			sql+=" where sd.stka in ("+s_IDtk+")";
			if(s_IDlk!="")sql+=" and sd.lk="+s_IDlk;
			if(s_IDchuong!="")sql+=" and sd.chuong="+s_IDchuong;
			if(s_IDhoatdong!="")sql+=" and sd.hoatdong="+s_IDhoatdong;
			if(s_IDnhombc!="")sql+=" and sd.idbc="+s_IDnhombc;
			if(s_IDdoituong!="")sql+=" and sd.madt='"+s_IDdoituong+"'";
			if(s_IDmuc!="")sql+=" and sd.mtmuc='"+s_IDmuc+"'";
			if (s_IDkm!="") sql+=" and sd.khoanmuc = '"+s_IDkm+"'";		
			if (s_IDkm2!="") sql+=" and sd.khoanmuc2 = '"+s_IDkm2+"'";			
			if (s_IDkm3!="") sql+=" and sd.khoanmuc3 = '"+s_IDkm3+"'";			
			if (s_IDkm4!="") sql+=" and sd.khoanmuc4 = '"+s_IDkm4+"'";
			sql+=" "+s_DKwhere+"";
			sql+=""+s_DKGroupbygroup+"";				
            
			ds=get_data(sql);			
			//catch{return null;};
			if(ds!=null && ds.Tables[0].Rows.Count>0)
				return ds;
			else return null;

		}
		public decimal get_Sodudauky(string s_mm,string s_yy,string s_IDchuong,string s_IDtk,string s_IDlk,string s_IDkm,string s_IDhoatdong,string s_IDnhombc,int i_Loaiton,string s_IDdoituong, string s_IDmuc,string s_IDkm2,string s_IDkm3,string s_IDkm4)
		{
			//Neu i_Loaiton==1 lay sdno, neu i_Loaiton==1 lay sdco, neu i_Loaiton==3 lay sdno-sdco.
			decimal d_Sodudk=0;			
			switch (i_Loaiton)
			{
				case 1:
				{
					sql=  "select sum(sd.sdno"+s_mm+") sddauky";
					sql+=" from a_sd"+s_yy+" sd"; 
					break;
				}
				case 2:
				{
					sql=  "select sum(sd.sdco"+s_mm+") sddauky";
					sql+=" from a_sd"+s_yy+" sd"; 
					break;
				}
				case 3:
				{
					sql=  "select sum(sd.sdno"+s_mm+" - sd.sdco"+s_mm+") sddauky";
					sql+=" from a_sd"+s_yy+" sd"; 
					break;
				}
				default:
				{
					sql=  "select 0 sddauky";
					sql+=" from a_sd"+s_yy+" sd"; 
					break;
				}
			}
			sql+=" where sd.stka in("+s_IDtk+")";
			if (s_IDchuong!="") sql+=" and chuong='"+s_IDchuong+"'";
			if (s_IDlk!="") sql+=" and lk='"+s_IDlk+"'";			
			if (s_IDhoatdong!="") sql+=" and hoatdong='"+s_IDhoatdong+"'";
			if (s_IDnhombc!="") sql+=" and idbc='"+s_IDnhombc+"'";
			if(s_IDdoituong!="")sql+=" and madt='"+s_IDdoituong+"'";
			if(s_IDmuc!="")sql+=" and mtmuc='"+s_IDmuc+"'";
			if (s_IDkm!="") sql+=" and khoanmuc = '"+s_IDkm+"'";		
			if (s_IDkm2!="") sql+=" and khoanmuc2 = '"+s_IDkm2+"'";			
			if (s_IDkm3!="") sql+=" and khoanmuc3 = '"+s_IDkm3+"'";			
			if (s_IDkm4!="") sql+=" and khoanmuc4 = '"+s_IDkm4+"'";
			try
			{
				d_Sodudk=decimal.Parse(get_data(sql).Tables[0].Rows[0][0].ToString());
			}
			catch{};
			return d_Sodudk;
		}
		public decimal get_FSluykequy(string s_mm,string s_yy,string s_IDchuong,string s_IDtk,string s_IDlk,string s_IDkm,string s_IDhoatdong,string s_IDnhombc,int i_Loaitk,string s_IDdoituong,string s_IDmuc,string s_IDkm2,string s_IDkm3,string s_IDkm4)
		{
			decimal d_FSluyke=0;
			int i_den=int.Parse(s_mm);
			int i_tu=((i_den-1)/3)*3+1;
			for (int i=i_tu;i<i_den;i++)
			{
				string s_Thang_i=i.ToString().PadLeft(2,'0');
				if (i_Loaitk==1) sql=  "select sum(sd.fsno"+s_Thang_i+") fsluyke";
				else sql=  "select sum(sd.fsco"+s_Thang_i+") fsluyke";
				sql+=" from a_sd"+s_yy+" sd"; 
				sql+=" where sd.stka in("+s_IDtk+")";
				if (s_IDchuong!="") sql+=" and chuong='"+s_IDchuong+"'";
				if (s_IDlk!="") sql+=" and lk='"+s_IDlk+"'";				
				if (s_IDhoatdong!="") sql+=" and hoatdong='"+s_IDhoatdong+"'";
				if (s_IDnhombc!="") sql+=" and idbc='"+s_IDnhombc+"'";
				if(s_IDdoituong!="")sql+=" and madt='"+s_IDdoituong+"'";
				if(s_IDmuc!="")sql+=" and mtmuc='"+s_IDmuc+"'";
				if (s_IDkm!="") sql+=" and khoanmuc = '"+s_IDkm+"'";		
				if (s_IDkm2!="") sql+=" and khoanmuc2 = '"+s_IDkm2+"'";			
				if (s_IDkm3!="") sql+=" and khoanmuc3 = '"+s_IDkm3+"'";			
				if (s_IDkm4!="") sql+=" and khoanmuc4 = '"+s_IDkm4+"'";
				try
				{
					d_FSluyke+=decimal.Parse(get_data(sql).Tables[0].Rows[0][0].ToString());
				}
				catch{};
			}
			return d_FSluyke;
		}
		public decimal get_FSluykenam(string s_mm,string s_yy,string s_IDchuong,string s_IDtk,string s_IDlk,string s_IDkm,string s_IDhoatdong,string s_IDnhombc,int i_Loaitk,string s_IDdoituong,string s_IDmuc,string s_IDkm2,string s_IDkm3,string s_IDkm4)
		{
			//i_Loaitk=1 : lay luy ke phat sinh no, i_Loaitk=2 : lay luy ke phat sinh co.
			decimal d_FSluyke=0;
			int i_den=int.Parse(s_mm);
			for (int i=1;i<i_den;i++)
			{
				string s_Thang_i=i.ToString().PadLeft(2,'0');
				if (i_Loaitk==1) sql=  "select sum(sd.fsno"+s_Thang_i+") fsluyke";
				else sql=  "select sum(sd.fsco"+s_Thang_i+") fsluyke";
				sql+=" from a_sd"+s_yy+" sd"; 
				sql+=" where sd.stka in("+s_IDtk+")";
				if (s_IDchuong!="") sql+=" and chuong='"+s_IDchuong+"'";
				if (s_IDlk!="") sql+=" and lk='"+s_IDlk+"'";				
				if (s_IDhoatdong!="") sql+=" and hoatdong='"+s_IDhoatdong+"'";
				if (s_IDnhombc!="") sql+=" and idbc='"+s_IDnhombc+"'";
				if(s_IDdoituong!="")sql+=" and madt='"+s_IDdoituong+"'";
				if(s_IDmuc!="")sql+=" and mtmuc='"+s_IDmuc+"'";
				if (s_IDkm!="") sql+=" and khoanmuc = '"+s_IDkm+"'";		
				if (s_IDkm2!="") sql+=" and khoanmuc2 = '"+s_IDkm2+"'";			
				if (s_IDkm3!="") sql+=" and khoanmuc3 = '"+s_IDkm3+"'";			
				if (s_IDkm4!="") sql+=" and khoanmuc4 = '"+s_IDkm4+"'";
				try
				{
					d_FSluyke+=decimal.Parse(get_data(sql).Tables[0].Rows[0][0].ToString());
				}
				catch{};
			}
			return d_FSluyke;
		}
		public DataSet get_FSluykenamdt(string s_mm,string s_yy,string s_IDchuong,string s_IDtk,string s_IDlk,string s_IDkm,string s_IDhoatdong,string s_IDnhombc,int i_dkgroup,string s_IDdoituong,string s_IDmuc,string s_IDkm2,string s_IDkm3,string s_IDkm4,int i)
		{			
			string s_DKSelectgroup="",s_DKGroupbygroup="";
			string sql="";
			string s_DKgroup="", s_DKwhere="";
			string s_DKfrom="";
			if(i_dkgroup!=-1) s_DKgroup=", "+i_dkgroup+" as nhom";
			else s_DKgroup=", -1 as nhom ";	
			switch(i_dkgroup)
			{
				case 0:
					s_DKSelectgroup=" sd.chuong as idchuong, ch.ten as chuong,";
					s_DKGroupbygroup=" group by sd.chuong, ch.ten";
					s_DKfrom=" , "+user+".a_dmchuong ch";
					s_DKwhere=" and sd.chuong=ch.id";
					break;
				case 1:
					s_DKSelectgroup=" sd.madt as iddoituong, dt.tendt as doituong,";
					s_DKGroupbygroup=" group by sd.madt,dt.tendt";
					s_DKfrom=" , "+user+".a_dmdt dt";
					s_DKwhere=" and sd.madt=dt.id";
					break;
				case 2:
					s_DKSelectgroup=" sd.hoatdong as idhoatdong, hd.ten as hoatdong,";
					s_DKGroupbygroup=" group by sd.hoatdong,hd.ten";
					s_DKfrom=" , "+user+".a_hoatdong hd";
					s_DKwhere=" and sd.hoatdong=hd.id";
					break;
				case 3:
					s_DKSelectgroup=" sd.mtmuc as idmuc, ch.ttk as muc,";
					s_DKGroupbygroup=" group by sd.mtmuc,ch.ttk";
					s_DKfrom=" , "+user+".a_dmch ch";
					s_DKwhere=" and sd.mtmuc=ch.id";
					break;
				case 4:
					s_DKSelectgroup=" sd.idbc as idnhombc, bc.ten as nhombc, ";
					s_DKGroupbygroup=" group by sd.idbc,bc.ten";
					s_DKfrom=" , "+user+".a_dmnhombc bc";
					s_DKwhere=" and sd.idbc=bc.id";
					break;
				case 5:
					s_DKSelectgroup=" sd.khoanmuc as idkm, km.ten as km,";
					s_DKGroupbygroup=" group by sd.khoanmuc,km.ten";
					s_DKfrom=" , "+user+".a_dmkhoanmuc km";
					s_DKwhere=" and sd.khoanmuc=km.id";
					break;
				case 6:
					s_DKSelectgroup=" sd.khoanmuc2 as idkm2, km.ten as km2,";
					s_DKGroupbygroup=" group by sd.khoanmuc2,km.ten";
					s_DKfrom=" , "+user+".a_dmkhoanmuc km";
					s_DKwhere=" and sd.khoanmuc2=km.id";
					break;
				case 7:
					s_DKSelectgroup=" sd.khoanmuc3 as idkm3, km.ten as km3,";
					s_DKGroupbygroup=" group by sd.khoanmuc3,km.ten";
					s_DKfrom=" , "+user+".a_dmkhoanmuc km";
					s_DKwhere=" and sd.khoanmuc3=km.id";
					break;
				case 8:
					s_DKSelectgroup=" sd.khoanmuc4 as idkm4, km.ten as km4,";
					s_DKGroupbygroup=" group by sd.khoanmuc4,km.ten";
					s_DKfrom=" , "+user+".a_dmkhoanmuc km";
					s_DKwhere=" and sd.khoanmuc4=km.id";
					break;
				default: 
					s_DKSelectgroup="";
					s_DKGroupbygroup=" group by sd.stka";
					break;
			}
			string s_Thang_i=i.ToString().PadLeft(2,'0');
			sql=  "select sum(sd.fsno"+s_Thang_i+") fsluyke_no,-2 as sapxep";				
			sql+=" "+s_DKgroup+",";
			sql+=" "+s_DKSelectgroup+"";
			sql+=  " sum(sd.fsco"+s_Thang_i+") fsluyke_co,0 as sotienthu, 0 as sotienchi";
			sql+=" from a_sd"+s_yy+" sd"; 
			sql+=" "+s_DKfrom+"";
			sql+=" where sd.stka in("+s_IDtk+")";
			if (s_IDchuong!="") sql+=" and chuong='"+s_IDchuong+"'";
			if (s_IDlk!="") sql+=" and lk='"+s_IDlk+"'";				
			if (s_IDhoatdong!="") sql+=" and hoatdong='"+s_IDhoatdong+"'";
			if (s_IDnhombc!="") sql+=" and idbc='"+s_IDnhombc+"'";
			if(s_IDdoituong!="")sql+=" and madt='"+s_IDdoituong+"'";
			if(s_IDmuc!="")sql+=" and mtmuc='"+s_IDmuc+"'";
			if (s_IDkm!="") sql+=" and khoanmuc = '"+s_IDkm+"'";		
			if (s_IDkm2!="") sql+=" and khoanmuc2 = '"+s_IDkm2+"'";			
			if (s_IDkm3!="") sql+=" and khoanmuc3 = '"+s_IDkm3+"'";			
			if (s_IDkm4!="") sql+=" and khoanmuc4 = '"+s_IDkm4+"'";	
			sql+=" "+s_DKwhere+"";
			sql+=" "+s_DKGroupbygroup+"";
			ds=get_data(sql);
			//catch{return null;};
			if(ds!=null && ds.Tables[0].Rows.Count>0)
				return ds;
			else return null;
		}
		public DataSet get_data_3sql(string sql,string sql1,string sql2)
		{		
			try
			{
				con=new OracleConnection(sConn);
				con.Open();
				ds=new DataSet();

				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				dest=new OracleDataAdapter(cmd);
				dest.Fill(ds,"Table");	

				OracleCommand cmd1=new OracleCommand(sql1,con);
				cmd1.CommandType=CommandType.Text;
				dest=new OracleDataAdapter(cmd1);
				dest.Fill(ds,"Table1");

				OracleCommand cmd2=new OracleCommand(sql2,con);
				cmd2.CommandType=CommandType.Text;
				dest=new OracleDataAdapter(cmd2);
				dest.Fill(ds,"Table2");

				cmd1.Dispose();
				cmd2.Dispose();
				cmd.Dispose();				
				con.Dispose();
			}
			catch(OracleException ex)
			{
				cmd.Dispose();		
				con.Dispose();
				upd_error(ex.Message.ToString().Trim(),sComputer,"?");
			}
			return ds;
		}
		public decimal get_FSluykenam(string s_yy,string s_IDlk,int i_Loaitk,int i_tu,string s_IDChuong, string s_IDHoatdong, string s_IDNhombc,string s_IDNguon)// bool b_checkChuong, string idChuong, bool b_checkHoatDong, string idHoatDong, string idNhombc, bool b_checkNhombc)
		{
			decimal d_FSluyke=0;
			for (int i=1;i<i_tu;i++)
			{
				string s_Thang_i=i.ToString().PadLeft(2,'0');
				if (i_Loaitk==1) sql=  "select sum(sd.fsno"+s_Thang_i+") fsluyke";
				else sql=  "select sum(sd.fsco"+s_Thang_i+") fsluyke";
				sql+=" from "+user+".a_sd"+s_yy+" sd inner join "+user+".a_dmtk b on sd.stka=b.id";
				sql+=" inner join "+user+".a_dmng c on (substr(b.stk,7,length(trim(b.stk)))=c.mang";
				sql+=" or substr(b.stk,6,length(trim(b.stk)))=c.mang)";
				sql+=" where c.id = " +s_IDNguon;
				if(s_IDHoatdong=="1")
				{
					sql+=" and (b.stk like '46111%' or b.stk like '46121%' or b.stk like '66111%'or b.stk like '66121%')";
				}
				else
					if(s_IDHoatdong=="2")
				{
					sql+=" and (b.stk like '46112%' or b.stk like '46122%' or b.stk like '66112%' or b.stk like '66122%')";
			//		sql+="	and substr(b.stk,7,length(trim(b.stk)))=c.mang ";
				}
				else
					if(s_IDHoatdong=="0")
					sql+=" and (b.stk like '462%' or b.stk like '662%')";
				if (s_IDlk!="") sql+=" and lk='"+s_IDlk+"'";
				if(s_IDChuong!="")sql+=" and sd.chuong="+s_IDChuong;
				if(s_IDHoatdong!="")sql+=" and sd.hoatdong="+s_IDHoatdong;
				if(s_IDNhombc!="")sql+=" and sd.idbc="+s_IDNhombc;
				try
				{
					d_FSluyke+=decimal.Parse(get_data(sql).Tables[0].Rows[0][0].ToString());
				}
				catch{};
			}
			return d_FSluyke;
		}	
		public decimal get_FSluykenam_quy(string s_yy,string s_sotk,string s_IDlk,int i_Loaitk, int CT_Quy,int i_tu,string s_IDChuong, string s_IDHoatdong,string s_IDNhombc,string s_IDdoituong,string s_IDmuc,string s_IDkm,string s_IDkm2,string s_IDkm3,string s_IDkm4)// bool b_checkChuong, string idChuong, bool b_checkHoatDong, string idHoatDong, string idNhombc, bool b_checkNhombc)
		{
			decimal d_FSluyke=0;
			for (int i=CT_Quy;i<i_tu;i++)
			{
				string s_Thang_i=i.ToString().PadLeft(2,'0');
				if (i_Loaitk==1) sql=  "select sum(sd.fsno"+s_Thang_i+") fsluyke";
				else sql=  "select sum(sd.fsco"+s_Thang_i+") fsluyke";
				sql+=" from a_sd"+s_yy+" sd,a_dmtk b";
				sql+=" where sd.stka=b.id and b.stk like '"+s_sotk+"%'";
				if (s_IDlk!="") sql+=" and lk='"+s_IDlk+"'";
				if(s_IDChuong!="")sql+=" and sd.chuong="+s_IDChuong;
				if(s_IDHoatdong!="")sql+=" and sd.hoatdong="+s_IDHoatdong;
				if(s_IDNhombc!="")sql+=" and sd.idbc="+s_IDNhombc;
				if(s_IDdoituong!="")sql+=" and madt='"+s_IDdoituong+"'";
				if(s_IDmuc!="")sql+=" and sd.mtmuc='"+s_IDmuc+"'";
				if (s_IDkm!="") sql+=" and sd.khoanmuc = '"+s_IDkm+"'";		
				if (s_IDkm2!="") sql+=" and sd.khoanmuc2 = '"+s_IDkm2+"'";			
				if (s_IDkm3!="") sql+=" and sd.khoanmuc3 = '"+s_IDkm3+"'";			
				if (s_IDkm4!="") sql+=" and sd.khoanmuc4 = '"+s_IDkm4+"'";

				try
				{
					d_FSluyke+=decimal.Parse(get_data(sql).Tables[0].Rows[0][0].ToString());
				}
				catch{};
			}
			return d_FSluyke;
		}	
		public string get_SdDauKy_muc(string s_yy,string s_mm,string s_sotk,string s_IDMuc,string s_IDlk,string s_IDChuong,string s_IDHoatdong,string s_IDNhombc)// bool b_CheckChuong, string s_IDChuong, bool b_CheckHoatDong, string s_IDHoatdong, string s_IDNhombc, bool b_CheckNhombc)
		{
			string sql="";	

			sql=" select t2.tenmuc,t1.* from (";			
			sql+="select case when (b.stk in (select b.stk as muc from a_sd"+s_yy+" a,";
			sql+=" a_dmch b where a.mtmuc=b.id)) then sum(sdno"+s_mm+") else 0 end as sodu_no,";
			sql+=" case when (b.stk in (select b.stk as muc from a_sd"+s_yy+" a,";
			sql+=" a_dmch b where a.mtmuc=b.id )) then sum(sdco"+s_mm+") else 0 end as sodu_co,";
			sql+=" 0 as no,0 as co, 0 as luyke_no,0 as luyke_co,";
			sql+=" substr(b.mtm,0,4) as muc,'' ttk ";
			sql+=" from "+user+".a_dmtk c inner join "+user+".a_sd"+s_yy+" a on c.id=a.stka";
			sql+=" left join "+user+".a_dmch b on a.mtmuc=b.id";
			sql+=" where c.stk like '"+s_sotk+"%'";
			if(s_IDMuc!="") sql+= " and b.mtm like'"+s_IDMuc+"%'";
			if (s_IDlk!="") sql+=" and a.lk="+s_IDlk;
			if(s_IDChuong!="")sql+=" and a.chuong="+s_IDChuong;
			if(s_IDHoatdong!="")sql+=" and a.hoatdong="+s_IDHoatdong;
			if(s_IDNhombc!="")sql+=" and a.idbc="+s_IDNhombc;
			sql+=" group by b.stk, b.mtm";
			sql+=" ) t1 left join (select ch.mtm as muc,ch.ttk as tenmuc from a_dmch ch) t2 on t1.muc=t2.muc";
			return sql;
		}
		public System.Data.DataSet get_DMTaikhoan(string s_Sotk)
		{
			if (s_Sotk!="")								
				sql=" select stk,ttk,congno,tinhchat,mlns,ctmlns,loaikm,loaikm2,loaikm3,loaikm4,id from "+user+".a_dmtk where trim(stk) like '"+s_Sotk+"%' and sudung=1 order by stk";
			else 
				sql=" select stk,ttk,congno,tinhchat,mlns,ctmlns,loaikm,loaikm2,loaikm3,loaikm4,id from "+user+".a_dmtk where sudung=1 order by stk";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}
		public string get_FSluykenam_muc(string s_yy,int tuthang,string s_sotk,string s_IDMuc,string s_IDlk,string s_IDChuong, string s_IDHoatdong, string s_IDNhombc)// bool b_CheckChuong, string s_IDChuong, bool b_CheckHoatDong, string s_IDHoatdong, string s_IDNhombc, bool b_CheckNhombc)
		{
			string sql="";		
			sql=" select t2.tenmuc,t1.* from (";				
			for (int i=0;i<tuthang;i++)
			{
				string s_Thang_i=i.ToString().PadLeft(2,'0');
				if(i==0)sql=" select 0 luyke_no, 0 luyke_co,";
				else
				{
					sql=  "select sum(sd.fsno"+s_Thang_i+") luyke_no,";
					sql+=  "sum(sd.fsco"+s_Thang_i+") luyke_co,";
				}
				sql+=" substr(trim(mtm),6,length(trim(mtm))) as tmtm, substr(trim(mtm),0,4) as muc,";
				sql+=" substr(trim(mtm),6,4) as tm, '' ttk,";
				sql+=" 0 as no,0 as co,0 as sodu_no,0 as sodu_co";
				sql+=" from a_sd"+s_yy+" sd, a_dmch b, a_dmtk c"; 
				sql+=" where sd.mtmuc=b.id";
				sql+= " and sd.stka=c.id";
				sql+=" and c.stk like '"+s_sotk+"%'";
				if(s_IDMuc!="") sql+=" and b.mtm like '"+s_IDMuc+"%'";
				if (s_IDlk!="") sql+=" and lk='"+s_IDlk+"'";
				if(s_IDChuong!="")sql+=" and sd.chuong="+s_IDChuong;
				if(s_IDHoatdong!="")sql+=" and sd.hoatdong="+s_IDHoatdong;
				if(s_IDNhombc!="")sql+=" and sd.idbc="+s_IDNhombc;
				sql+=" group by b.stk,mtm";
				sql+=" ) t1 inner join (select ch.mtm as muc,ch.ttk as tenmuc from a_dmch ch) t2 on t1.muc=t2.muc";
	                			
			}				
			return sql;
		}
		public System.Data.DataSet get_DMNguon(string loaikp)
		{
			sql="select mang, ten,mang||'_'||ten as tenng,id from "+user+".a_dmng";	
			if(loaikp!="")sql+=" where loaikp="+loaikp+"";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}
		public System.Data.DataSet get_DMHoatdong(string s_form)
		{
			if(s_form=="tc_CTkinhphihoatdong")
				sql="select ma,ten,id,stt from a_hoatdong where sudung=1 and id=1 or id=2 order by ma";
			else
				if(s_form=="tc_CTkinhphiduan")
				sql="select ma,ten,id,stt from a_hoatdong where sudung=1 and id=0 order by ma";
			else
				sql="select ma,ten,id,stt from a_hoatdong where sudung=1 order by ma";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}
		public DataSet get_SdDauKy_muc_tm(string s_yy,string s_mm,string s_IDMuc,string s_IDlk, string s_IDChuong, string s_IDHoatDong, string s_IDNhombc,string s_IDnguon)
		{
			string sql="";	
			sql=" select t1.*,t2.td_muc";
			sql+=" from (";
			sql+=" select sum(sdno"+s_mm+") as sd_no, sum(sdco"+s_mm+") as sd_co,";
			sql+=" stka, tk.stk as stk,ch.ttk as chitieu,";
			sql+=" case when length(trim(ch.mtm))>3 then substr(trim(ch.mtm),0,4) else '' end as muc,";
			sql+=" case when length(trim(ch.mtm))>8 then substr(trim(ch.mtm),6,4) else '' end as tm,";
			sql+=" nh.nhom as nhommuc,lk.lk as lk,substr(trim(lk.lk),0,3) as loai, substr(trim(lk.lk),5,3) as khoan,";
			sql+=" 0 as no, 0 as co,0 as sd";
			sql+=" from "+user+".a_sd"+s_yy+" sd inner join "+user+".a_dmch ch on sd.mtmuc=ch.id";
			sql+=" inner join "+user+".a_dmlk lk on lk.id=sd.lk";	
			sql+=" inner join "+user+".a_dmtk tk on tk.id=sd.stka";
			sql+=" inner join "+user+".a_dmng ng on substr(trim(tk.stk), 7, length(trim(tk.stk)))= ng.mang";
			sql+=" left join "+user+".a_dmnhom nh on nh.id=ch.nhmuc";
			sql+=" where sd.hoatdong="+s_IDHoatDong;
			sql+=" and ng.id="+s_IDnguon+"";
			if(s_IDMuc!="") sql+= " and ch.mtm like'"+s_IDMuc+"%'";
			if (s_IDlk!="") sql+=" and sd.lk="+s_IDlk;
			if(s_IDChuong!="")sql+=" and sd.chuong="+s_IDChuong;
			//if(s_IDHoatDong!="")sql+=" and sd.hoatdong="+s_IDHoatDong;
			if(s_IDNhombc!="")sql+=" and sd.idbc="+s_IDNhombc;
			sql+=" group by case when length(trim(ch.mtm))>3 then substr(trim(ch.mtm),0,4) else '' end,";
			sql+=" case when length(trim(ch.mtm))>8 then substr(trim(ch.mtm),6,4) else '' end,";
			sql+=" nh.nhom,substr(trim(lk.lk),0,3),substr(trim(lk.lk),5,3),";
			sql+=" stka,tk.stk,lk.lk,ch.ttk";
			sql+=")t1";
			sql+=" left join ";
			sql+="(select mtm as muc, ttk as td_muc from "+user+".a_dmch) t2 on t1.muc=t2.muc";		
			
			ds=get_data(sql);		
			//duyet so lieu, tinh so du 
			if(ds!=null && ds.Tables[0].Rows.Count>0)
			{
				long l_sdno=0,l_sdco=0,l_sd461=0,l_sd661=0,l_sd=0;
				string s_tk="";
				int count_=ds.Tables[0].Rows.Count;

				foreach(DataRow re in ds.Tables[0].Rows)
				{
					l_sdno=0;l_sdco=0;l_sd461=0;l_sd661=0;l_sd=0;
					s_tk=re["stk"].ToString();
					l_sdco=long.Parse(re["sd_co"].ToString());
					l_sdno=long.Parse(re["sd_no"].ToString());
					if(s_tk.Trim().Length>3 && s_tk.Trim().Substring(0,3)=="461")
					{
						l_sd461+=l_sdco-l_sdno;
					}
					if(s_tk.Trim().Length>3 && s_tk.Trim().Substring(0,3)=="661")
					{
						l_sd661+=l_sdno-l_sdco;
					}
					l_sd+=l_sd461-l_sd661;
					re["sd"]=l_sd;
					ds.AcceptChanges();
				}

//				for(int i=0;i<=count_-1;i++)
//				{
//					l_sdno=0;l_sdco=0;l_sd461=0;l_sd661=0;l_sd=0;
//					s_tk=ds.Tables[0].Rows[i]["stk"].ToString();
//					l_sdco=Convert.ToInt32(ds.Tables[0].Rows[i]["sd_co"].ToString());
//					l_sdno=Convert.ToInt32(ds.Tables[0].Rows[i]["sd_no"].ToString());
//					if(s_tk.Trim().Length>3 && s_tk.Trim().Substring(0,3)=="461")
//					{
//						l_sd461+=l_sdco-l_sdno;
//					}
//					if(s_tk.Trim().Length>3 && s_tk.Trim().Substring(0,3)=="661")
//					{
//						l_sd661+=l_sdno-l_sdco;
//					}
//					l_sd+=l_sd461-l_sd661;
//					ds.Tables[0].Rows[i]["sd"]=l_sd;
//					ds.AcceptChanges();
//				}
			}
			if(ds!=null && ds.Tables[0].Rows.Count>0)
                return ds;
			else return null;
		}	
		public DataSet get_SdDauKy_muc_tmda(string s_yy,string s_mm,string s_IDMuc,string s_IDlk, string s_IDChuong, string s_IDHoatDong, string s_IDNhombc,string s_IDnguon)
		{
			string sql="";
			sql=" select t1.*,t2.td_muc";
			sql+=" from (";
			sql+=" select sum(sdno"+s_mm+") as sd_no, sum(sdco"+s_mm+") as sd_co,";
			sql+=" stka, tk.stk as stk,ch.ttk as chitieu,";	
			sql+=" case when length(trim(ch.mtm))>3 then substr(trim(ch.mtm),0,4) else '' end as muc,";
			sql+=" case when length(trim(ch.mtm))>8 then substr(trim(ch.mtm),6,4) else '' end as tm,";
			sql+=" nh.nhom as nhommuc,lk.lk as lk,substr(trim(lk.lk),0,3) as loai, substr(trim(lk.lk),5,3) as khoan,";
			sql+=" 0 as no, 0 as co,0 as sd,0 as sdn,0 as cot021,0 as cot051,0 as cot041,0 as d_fs,0 as d_lk";
			sql+=" from "+user+".a_sd"+s_yy+" sd inner join "+user+".a_dmch ch on sd.mtmuc=ch.id";			
			sql+=" inner join "+user+".a_dmtk tk on tk.id=sd.stka";
			sql+=" inner join "+user+".a_dmlk lk on lk.id=sd.lk";			
			sql+=" left join "+user+".a_dmnhom nh on nh.id=ch.nhmuc";
			sql+=" inner join "+user+".a_dmng ng on substr(trim(tk.stk), 6, length(trim(tk.stk)))= ng.mang";
			sql+=" where sd.hoatdong="+s_IDHoatDong;
			sql+=" and ng.id="+s_IDnguon+"";
			if(s_IDMuc!="") sql+= " and ch.mtm like '"+s_IDMuc+"%'";
			if (s_IDlk!="") sql+=" and sd.lk="+s_IDlk;
			if(s_IDChuong!="")sql+=" and sd.chuong="+s_IDChuong;
			//if(s_IDHoatDong!="")sql+=" and sd.hoatdong="+s_IDHoatDong;
			if(s_IDNhombc!="")sql+=" and sd.idbc="+s_IDNhombc;
			sql+=" group by stka,tk.stk,";
			sql+=" case when length(trim(ch.mtm))>3 then substr(trim(ch.mtm),0,4) else '' end,";
			sql+=" case when length(trim(ch.mtm))>8 then substr(trim(ch.mtm),6,4) else '' end,";
			sql+=" nh.nhom,substr(trim(lk.lk),0,3),substr(trim(lk.lk),5,3),";
			sql+=" lk.lk,ch.ttk";
			sql+=")t1";
			sql+=" left join ";
			sql+="(select mtm as muc, ttk as td_muc from "+user+".a_dmch) t2 on t1.muc=t2.muc";
			ds=get_data(sql);		
			//duyet so lieu, tinh so du 
			if(ds!=null && ds.Tables[0].Rows.Count>0)
			{
				//ds.Tables[0].Columns.Add("sapxep",typeof(System.Int32));
				long l_sdno=0,l_sdco=0,l_sd462=0,l_sd662=0,l_sd=0;
				string s_tk="";
				int count_=ds.Tables[0].Rows.Count;
				for(int i=0;i<=count_-1;i++)
				{
					l_sdno=0;l_sdco=0;l_sd462=0;l_sd662=0;l_sd=0;
					s_tk=ds.Tables[0].Rows[i]["stk"].ToString();
					l_sdco=Convert.ToInt32(ds.Tables[0].Rows[i]["sd_co"].ToString());
					l_sdno=Convert.ToInt32(ds.Tables[0].Rows[i]["sd_no"].ToString());					
					if(s_tk.Trim().Length>3 && s_tk.Trim().Substring(0,3)=="462")
					{
						l_sd462+=l_sdco-l_sdno;
					}
					if(s_tk.Trim().Length>3 && s_tk.Trim().Substring(0,3)=="662")
					{
						l_sd662+=l_sdno-l_sdco;
					}
					l_sd+=l_sd462-l_sd662;
					ds.Tables[0].Rows[i]["sd"]=l_sd;
					//ds.Tables[0].Rows[i]["sapxep"]=0;
					ds.AcceptChanges();
				}
			}
			if(ds==null||ds.Tables[0].Rows.Count<=0)return null;
                else return ds;
		}		
		public DataSet get_SdDauKy_mKPI(string s_yy,string s_mm,string s_IDMuc,string s_IDlk, string s_IDChuong, string s_IDHoatDong, string s_IDNhombc,string s_IDnguon)
		{
			string sql="";
			sql=" select sum(sdno"+s_mm+") as sd_no, sum(sdco"+s_mm+") as sd_co,";
			sql+=" stka, tk.stk as stk,";	
			sql+=" lk.lk as lk,substr(trim(lk.lk),0,3) as loai, substr(trim(lk.lk),5,3) as khoan,";
			sql+=" 0 as d302, 0 as d306, 0 as d308, 0 as d402, 0 as d406,0 as d408,";
			sql+=" 0 as d502, 0 as d506, 0 as d508, 0 as d602, 0 as d606,0 as <=d608,";
			sql+=" 0 as d312, 0 as d316, 0 as d318, 0 as d412, 0 as d416,0 as d418,";
			sql+=" 0 as d512, 0 as d516, 0 as d518, 0 as d612, 0 as d616,0 as d618,";
			sql+=" 0 as d302_, 0 as d306_, 0 as d308_, 0 as d402_, 0 as d406_,0 as d408_,";
			sql+=" 0 as d502_, 0 as d506_, 0 as d508_, 0 as d602_, 0 as d606_,0 as d608_,";	
			sql+=" 0 as d802, 0 as d806, 0 as d808, 0 as d902, 0 as d906,0 as d908,";
			sql+=" 0 as d1002, 0 as d1006, 0 as d1008, 0 as d1102, 0 as d1106,0 as d1108,";
			sql+=" 0 as d812, 0 as d816, 0 as d818, 0 as d912, 0 as d916,0 as d918,";
			sql+=" 0 as d1012, 0 as d1016, 0 as d1018, 0 as d1112, 0 as d1116,0 as d1118,";
			sql+=" 0 as d802_, 0 as d806_, 0 as d808_, 0 as d902_, 0 as d906_,0 as d908_,";
			sql+=" 0 as d1002_, 0 as d1006_, 0 as d1008_, 0 as d1102_, 0 as d1106_,0 as d1108_,";	
			
			sql+=" 0 as d301, 0 as d311, 0 as d301_,";
			sql+=" 0 as d401, 0 as d411, 0 as d401_,";
			sql+=" 0 as d501, 0 as d511, 0 as d501_,";
			sql+=" 0 as d601, 0 as d611, 0 as d601_,";
			sql+=" 0 as d801, 0 as d811, 0 as d801_,";
			sql+=" 0 as d901, 0 as d911, 0 as d901_,";
			sql+=" 0 as d1001, 0 as d1011, 0 as d1001_,";
			sql+=" 0 as d1101, 0 as d1111, 0 as d1101_,";

			sql+=" 0 as d303, 0 as d307, 0 as d309, 0 as d403, 0 as d407,0 as d409,";
			sql+=" 0 as d503, 0 as d507, 0 as d509, 0 as d603, 0 as d607,0 as d609,";
			sql+=" 0 as d313, 0 as d317, 0 as d319, 0 as d413, 0 as d417,0 as d419,";
			sql+=" 0 as d513, 0 as d517, 0 as d519, 0 as d613, 0 as d617,0 as d619,";
			sql+=" 0 as d303_, 0 as d307_, 0 as d309_, 0 as d403_, 0 as d407_,0 as d409_,";
			sql+=" 0 as d503_, 0 as d507_, 0 as d509_, 0 as d603_, 0 as d607_,0 as d609_,";

			sql+=" 0 as d803, 0 as d807, 0 as d809, 0 as d903, 0 as d907,0 as d909,";
			sql+=" 0 as d1003, 0 as d1007, 0 as d1009, 0 as d1103, 0 as d1107,0 as d1109,";
			sql+=" 0 as d813, 0 as d817, 0 as d819, 0 as d913, 0 as d917,0 as d919,";
			sql+=" 0 as d1013, 0 as d1017, 0 as d1019, 0 as d1113, 0 as d1117,0 as d1119,";
			sql+=" 0 as d803_, 0 as d807_, 0 as d809_, 0 as d903_, 0 as d907_,0 as d909_,";
			sql+=" 0 as d1003_, 0 as d1007_, 0 as d1009_, 0 as d1103_, 0 as d1107_,0 as d1109_,";
			
			sql+=" 0 as no, 0 as co,'0' as phanloai,";
			sql+=" ng.mang,nv.id as idnghiepvu,nv.ten as tennghiepvu";
			sql+=" from "+user+".a_sd"+s_yy+" sd inner join "+user+".a_dmtk tk on tk.id=sd.stka";
			sql+=" inner join "+user+".a_dmlk lk on lk.id=sd.lk";			
			sql+=" inner join "+user+".a_dmng ng on (substr(trim(tk.stk),6,length(trim(tk.stk)))=ng.mang or ";
			sql+=" substr(trim(tk.stk),7,length(trim(tk.stk)))=ng.mang)";
			sql+=" left join "+user+".a_nghiepvu nv on sd.nghiepvu=nv.id";
			sql+=" inner join "+user+".a_dmch ch on ch.id=sd.mtmuc";
			
			sql+=" where (tk.stk like '461%' or tk.stk like '462' or tk.stk like '661' or tk.stk like '662%')";			
			if(s_IDHoatDong!="") sql+=" and sd.hoatdong="+s_IDHoatDong;
			if(s_IDnguon!="") sql+=" and ng.id="+s_IDnguon+"";
			if(s_IDMuc!="") sql+= " and ch.mtm like '"+s_IDMuc+"%'";
			if (s_IDlk!="") sql+=" and sd.lk="+s_IDlk;
			if(s_IDChuong!="")sql+=" and sd.chuong="+s_IDChuong;			
			if(s_IDNhombc!="")sql+=" and sd.idbc="+s_IDNhombc;
			sql+=" group by stka,tk.stk,";			
			sql+=" substr(trim(lk.lk),0,3),substr(trim(lk.lk),5,3),";
			sql+=" lk.lk,ng.mang,nv.id,nv.ten";
			ds=get_data(sql);		
			//duyet so lieu, tinh so du 
			try
			{
				if(ds!=null && ds.Tables[0].Rows.Count>0)
				{				
					//khai bao bien.
					decimal d_sdno=0,d_sdco=0,d_sd661_1=0,d_sd461_1=0,d_sd661_2=0;
					decimal d_sd461_2=0,d_sd662_1=0,d_sd462_1=0;
					//hoat dong thuong xuyen
					decimal d_301=0,d_401=0,d_501=0,d_601=0;
					decimal d_801=0,d_901=0,d_1001=0,d_1101=0;
					//hoat dong khong thuong xuyen
					decimal d_311=0,d_411=0,d_511=0,d_611=0;
					decimal d_811=0,d_911=0,d_1011=0,d_1111=0;
					//du an
					decimal d_301_=0,d_401_=0,d_501_=0,d_601_=0;
					decimal d_801_=0,d_901_=0,d_1001_=0,d_1101_=0;	

					string s_tk="",s_ngvu="",s_mang="";
					int count_=ds.Tables[0].Rows.Count;
					for(int i=0;i<=count_-1;i++)
					{
						//khoi tao gia tri bang 0 cho cac bien
						d_sdno=0;d_sdco=0;d_sd661_1=0;d_sd461_1=0;d_sd661_2=0;
						d_sd461_2=0;d_sd662_1=0;d_sd462_1=0;					
						//hoat dong thuong xuyen
						d_301=0;d_401=0;d_501=0;d_601=0;
						d_801=0;d_901=0;d_1001=0;d_1101=0;
						//hoat dong khong thuong xuyen
						d_311=0;d_411=0;d_511=0;d_611=0;
						d_811=0;d_911=0;d_1011=0;d_1111=0;
						//du an
						d_301_=0;d_401_=0;d_501_=0;d_601_=0;
						d_801_=0;d_901_=0;d_1001_=0;d_1101_=0;
						//gan gia tri cho cac bien.
						s_tk=ds.Tables[0].Rows[i]["stk"].ToString();
						s_ngvu=ds.Tables[0].Rows[i]["idnghiepvu"].ToString();
						s_mang=ds.Tables[0].Rows[i]["mang"].ToString();

						d_sdco=Convert.ToDecimal(ds.Tables[0].Rows[i]["sd_co"].ToString());
						d_sdno=Convert.ToDecimal(ds.Tables[0].Rows[i]["sd_no"].ToString());
					
						//kiem tra dk, do so lieu
						if(s_mang.Trim()=="0113")
						{
							if(s_tk.Trim()!="")
							{
								//hoat dong thuong xuyen
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46111") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46121"))
									d_sd461_1+=d_sdco-d_sdno;
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66111") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66121"))	
									d_sd661_1+=d_sdno-d_sdco;	
								d_301+=d_sd461_1-d_sd661_1;

								//hoat dong khong thuong xuyen
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46112") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46122"))
									d_sd461_2+=d_sdco-d_sdno;
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66112") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66122"))	
									d_sd661_2+=d_sdno-d_sdco;
								d_311+=d_sd461_2-d_sd661_2;

								//du an
								if(s_tk.Trim().Length>=3 && s_tk.Trim().Substring(0,3)=="462")
									d_sd462_1+=d_sdco-d_sdno;
								if(s_tk.Trim().Length>=3 && s_tk.Trim().Substring(0,3)=="662")	
									d_sd662_1+=d_sdno-d_sdco;
								d_301_+=d_sd462_1-d_sd662_1;							
							}
						}
						else
							if(s_mang.Trim()=="0212")
						{
							if(s_tk.Trim()!="")
							{
								//hoat dong thuong xuyen
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46111") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46121"))
									d_sd461_1+=d_sdco-d_sdno;
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66111") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66121"))	
									d_sd661_1+=d_sdno-d_sdco;	
								d_401+=d_sd461_1-d_sd661_1;

								//hoat dong khong thuong xuyen
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46112") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46122"))
									d_sd461_2+=d_sdco-d_sdno;
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66112") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66122"))	
									d_sd661_2+=d_sdno-d_sdco;
								d_411+=d_sd461_2-d_sd661_2;

								//du an
								if(s_tk.Trim().Length>=3 && s_tk.Trim().Substring(0,3)=="462")
									d_sd462_1+=d_sdco-d_sdno;
								if(s_tk.Trim().Length>=3 && s_tk.Trim().Substring(0,3)=="662")	
									d_sd662_1+=d_sdno-d_sdco;
								d_401_+=d_sd462_1-d_sd662_1;
							}
						}
						else
							if(s_mang.Trim().Substring(0,2)=="0214")
						{
							if(s_tk.Trim()!="")
							{
								//hoat dong thuong xuyen
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46111") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46121"))
									d_sd461_1+=d_sdco-d_sdno;
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66111") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66121"))	
									d_sd661_1+=d_sdno-d_sdco;	
								d_501+=d_sd461_1-d_sd661_1;

								//hoat dong khong thuong xuyen
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46112") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46122"))
									d_sd461_2+=d_sdco-d_sdno;
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66112") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66122"))	
									d_sd661_2+=d_sdno-d_sdco;
								d_511+=d_sd461_2-d_sd661_2;

								//du an
								if(s_tk.Trim().Length>=3 && s_tk.Trim().Substring(0,3)=="462")
									d_sd462_1+=d_sdco-d_sdno;
								if(s_tk.Trim().Length>=3 && s_tk.Trim().Substring(0,3)=="662")	
									d_sd662_1+=d_sdno-d_sdco;
								d_501_+=d_sd462_1-d_sd662_1;
							}
						}
						else 
							if(s_mang.Trim().Substring(0,2)=="0218")
						{
							if(s_tk.Trim()!="")
							{
								//hoat dong thuong xuyen
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46111") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46121"))
									d_sd461_1+=d_sdco-d_sdno;
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66111") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66121"))	
									d_sd661_1+=d_sdno-d_sdco;	
								d_601+=d_sd461_1-d_sd661_1;

								//hoat dong khong thuong xuyen
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46112") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46122"))
									d_sd461_2+=d_sdco-d_sdno;
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66112") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66122"))	
									d_sd661_2+=d_sdno-d_sdco;
								d_611+=d_sd461_2-d_sd661_2;

								//du an
								if(s_tk.Trim().Length>=3 && s_tk.Trim().Substring(0,3)=="462")
									d_sd462_1+=d_sdco-d_sdno;
								if(s_tk.Trim().Length>=3 && s_tk.Trim().Substring(0,3)=="662")	
									d_sd662_1+=d_sdno-d_sdco;
								d_601_+=d_sd462_1-d_sd662_1;
							}
						}
						else 
							if(s_mang.Trim().Substring(0,2)=="0401")
						{
							if(s_tk.Trim()!="")
							{
								//hoat dong thuong xuyen
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46111") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46121"))
									d_sd461_1+=d_sdco-d_sdno;
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66111") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66121"))	
									d_sd661_1+=d_sdno-d_sdco;	
								d_801+=d_sd461_1-d_sd661_1;

								//hoat dong khong thuong xuyen
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46112") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46122"))
									d_sd461_2+=d_sdco-d_sdno;
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66112") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66122"))	
									d_sd661_2+=d_sdno-d_sdco;
								d_811+=d_sd461_2-d_sd661_2;

								//du an
								if(s_tk.Trim().Length>=3 && s_tk.Trim().Substring(0,3)=="462")
									d_sd462_1+=d_sdco-d_sdno;
								if(s_tk.Trim().Length>=3 && s_tk.Trim().Substring(0,3)=="662")	
									d_sd662_1+=d_sdno-d_sdco;
								d_801_+=d_sd462_1-d_sd662_1;
							}
						}
						else
							if(s_mang.Trim().Substring(0,2)=="0501")
						{
							if(s_tk.Trim()!="")
							{
								//hoat dong thuong xuyen
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46111") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46121"))
									d_sd461_1+=d_sdco-d_sdno;
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66111") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66121"))	
									d_sd661_1+=d_sdno-d_sdco;	
								d_901+=d_sd461_1-d_sd661_1;

								//hoat dong khong thuong xuyen
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46112") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46122"))
									d_sd461_2+=d_sdco-d_sdno;
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66112") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66122"))	
									d_sd661_2+=d_sdno-d_sdco;
								d_911+=d_sd461_2-d_sd661_2;

								//du an
								if(s_tk.Trim().Length>=3 && s_tk.Trim().Substring(0,3)=="462")
									d_sd462_1+=d_sdco-d_sdno;
								if(s_tk.Trim().Length>=3 && s_tk.Trim().Substring(0,3)=="662")	
									d_sd662_1+=d_sdno-d_sdco;
								d_901_+=d_sd462_1-d_sd662_1;
							}
						}
						if(s_mang.Trim().Substring(0,2)=="0402")
						{
							if(s_tk.Trim()!="")
							{
								//hoat dong thuong xuyen
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46111") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46121"))
									d_sd461_1+=d_sdco-d_sdno;
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66111") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66121"))	
									d_sd661_1+=d_sdno-d_sdco;	
								d_1001+=d_sd461_1-d_sd661_1;

								//hoat dong khong thuong xuyen
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46112") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46122"))
									d_sd461_2+=d_sdco-d_sdno;
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66112") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66122"))	
									d_sd661_2+=d_sdno-d_sdco;
								d_1011+=d_sd461_2-d_sd661_2;

								//du an
								if(s_tk.Trim().Length>=3 && s_tk.Trim().Substring(0,3)=="462")
									d_sd462_1+=d_sdco-d_sdno;
								if(s_tk.Trim().Length>=3 && s_tk.Trim().Substring(0,3)=="662")	
									d_sd662_1+=d_sdno-d_sdco;
								d_1001_+=d_sd462_1-d_sd662_1;
							}
						}
						else
							if(s_mang.Trim().Substring(0,2)=="0502")
						{
							if(s_tk.Trim()!="")
							{
								//hoat dong thuong xuyen
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46111") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46121"))
									d_sd461_1+=d_sdco-d_sdno;
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66111") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66121"))	
									d_sd661_1+=d_sdno-d_sdco;	
								d_1101+=d_sd461_1-d_sd661_1;

								//hoat dong khong thuong xuyen
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46112") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="46122"))
									d_sd461_2+=d_sdco-d_sdno;
								if((s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66112") || (s_tk.Trim().Length>=5 && s_tk.Trim().Substring(0,5)=="66122"))	
									d_sd661_2+=d_sdno-d_sdco;
								d_1111+=d_sd461_2-d_sd661_2;

								//du an
								if(s_tk.Trim().Length>=3 && s_tk.Trim().Substring(0,3)=="462")
									d_sd462_1+=d_sdco-d_sdno;
								if(s_tk.Trim().Length>=3 && s_tk.Trim().Substring(0,3)=="662")	
									d_sd662_1+=d_sdno-d_sdco;
								d_1101_+=d_sd462_1-d_sd662_1;
							}
						}

						if((s_tk.Trim().Length>=3 && s_tk.Trim().Substring(0,3)=="462")|| (s_tk.Trim().Length>=3 && s_tk.Trim().Substring(0,3)=="662"))
							ds.Tables[0].Rows[i]["phanloai"]="II";
						else
							if((s_tk.Trim().Length>=3 && s_tk.Trim().Substring(0,3)=="461")|| (s_tk.Trim().Length>=3 && s_tk.Trim().Substring(0,3)=="661"))
							ds.Tables[0].Rows[i]["phanloai"]="I";
					
						ds.Tables[0].Rows[i]["d301"]=d_301;
						ds.Tables[0].Rows[i]["d311"]=d_311;
						ds.Tables[0].Rows[i]["d301_"]=d_301_;
						ds.Tables[0].Rows[i]["d401"]=d_401;
						ds.Tables[0].Rows[i]["d411"]=d_411;
						ds.Tables[0].Rows[i]["d401_"]=d_401_;
						ds.Tables[0].Rows[i]["d501"]=d_501;
						ds.Tables[0].Rows[i]["d511"]=d_511;
						ds.Tables[0].Rows[i]["d501_"]=d_501_;
						ds.Tables[0].Rows[i]["d601"]=d_601;
						ds.Tables[0].Rows[i]["d611"]=d_611;
						ds.Tables[0].Rows[i]["d601_"]=d_601_;	
						ds.Tables[0].Rows[i]["d801"]=d_801;
						ds.Tables[0].Rows[i]["d811"]=d_811;
						ds.Tables[0].Rows[i]["d801_"]=d_801_;
						ds.Tables[0].Rows[i]["d901"]=d_901;
						ds.Tables[0].Rows[i]["d911"]=d_911;
						ds.Tables[0].Rows[i]["d901_"]=d_901_;
						ds.Tables[0].Rows[i]["d1001"]=d_1001;
						ds.Tables[0].Rows[i]["d1011"]=d_1011;
						ds.Tables[0].Rows[i]["d1001_"]=d_1001_;
						ds.Tables[0].Rows[i]["d1101"]=d_1101;
						ds.Tables[0].Rows[i]["d1111"]=d_1111;
						ds.Tables[0].Rows[i]["d1101_"]=d_1101_;
						ds.AcceptChanges();
					}
				}			
			if(ds!=null&&ds.Tables[0].Rows.Count>0)
				return ds;
			else return null;
			}
			catch{return null;};
		}	
		public DataSet get_SdDauKyNam_muc_tmda(string s_yy,string s_IDMuc,string s_IDlk, string s_IDChuong, string s_IDHoatDong, string s_IDNhombc,string s_IDnguon)
		{
			string sql="";
			sql=" select t1.*,t2.td_muc";
			sql+=" from (";
			sql+=" select sum(sdno01) as sd_no, sum(sdco01) as sd_co,";
			sql+=" stka, tk.stk as stk,ch.ttk as chitieu,";	
			sql+=" case when length(trim(ch.mtm))>3 then substr(trim(ch.mtm),0,4) else '' end as muc,";
			sql+=" case when length(trim(ch.mtm))>8 then substr(trim(ch.mtm),6,4) else '' end as tm,";
			sql+=" nh.nhom as nhommuc,lk.lk as lk,substr(trim(lk.lk),0,3) as loai, substr(trim(lk.lk),5,3) as khoan,";
			sql+=" 0 as no, 0 as co,0 as sd,0 as sdn,0 as cot021,0 as cot051,0 as cot041";
			sql+=" from "+user+".a_sd"+s_yy+" sd inner join "+user+".a_dmch ch on sd.mtmuc=ch.id";			
			sql+=" inner join "+user+".a_dmtk tk on tk.id=sd.stka";
			sql+=" inner join "+user+".a_dmlk lk on lk.id=sd.lk";			
			sql+=" left join "+user+".a_dmnhom nh on nh.id=ch.nhmuc";
			sql+=" inner join "+user+".a_dmng ng on substr(trim(tk.stk), 6, length(trim(tk.stk)))= ng.mang";
			sql+=" where sd.hoatdong="+s_IDHoatDong;
			sql+=" and ng.id="+s_IDnguon+"";
			if(s_IDMuc!="") sql+= " and ch.mtm like '"+s_IDMuc+"%'";
			if (s_IDlk!="") sql+=" and sd.lk="+s_IDlk;
			if(s_IDChuong!="")sql+=" and sd.chuong="+s_IDChuong;
			//if(s_IDHoatDong!="")sql+=" and sd.hoatdong="+s_IDHoatDong;
			if(s_IDNhombc!="")sql+=" and sd.idbc="+s_IDNhombc;
			sql+=" group by stka,tk.stk,";
			sql+=" case when length(trim(ch.mtm))>3 then substr(trim(ch.mtm),0,4) else '' end,";
			sql+=" case when length(trim(ch.mtm))>8 then substr(trim(ch.mtm),6,4) else '' end,";
			sql+=" nh.nhom,substr(trim(lk.lk),0,3),substr(trim(lk.lk),5,3),";
			sql+=" lk.lk,ch.ttk";
			sql+=")t1";
			sql+=" left join ";
			sql+="(select mtm as muc, ttk as td_muc from "+user+".a_dmch) t2 on t1.muc=t2.muc";
			ds=get_data(sql);		
			//duyet so lieu, tinh so du 
			if(ds!=null && ds.Tables[0].Rows.Count>0)
			{
				//ds.Tables[0].Columns.Add("sapxep",typeof(System.Int32));
				long l_sdno=0,l_sdco=0,l_sd462=0,l_sd662=0,l_sd=0;
				string s_tk="";
				int count_=ds.Tables[0].Rows.Count;
				for(int i=0;i<=count_-1;i++)
				{
					l_sdno=0;l_sdco=0;l_sd462=0;l_sd662=0;l_sd=0;
					s_tk=ds.Tables[0].Rows[i]["stk"].ToString();
					l_sdco=Convert.ToInt32(ds.Tables[0].Rows[i]["sd_co"].ToString());
					l_sdno=Convert.ToInt32(ds.Tables[0].Rows[i]["sd_no"].ToString());					
					if(s_tk.Trim().Length>3 && s_tk.Trim().Substring(0,3)=="462")
					{
						l_sd462+=l_sdco-l_sdno;
					}
					if(s_tk.Trim().Length>3 && s_tk.Trim().Substring(0,3)=="662")
					{
						l_sd662+=l_sdno-l_sdco;
					}
					l_sd+=l_sd462-l_sd662;
					ds.Tables[0].Rows[i]["sdn"]=l_sd;
					//ds.Tables[0].Rows[i]["sapxep"]=0;
					ds.AcceptChanges();
				}
			}
			//catch{return null;};
			if(ds!=null&&ds.Tables[0].Rows.Count>0)
				return ds;
			else return null;
		}	
		public System.Data.DataSet get_DMloaidt()
		{
			sql="select * from "+user+".a_dmloaidt where sudung=1 order by id";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}
		public bool upd_dmch(int id,string ttk)
		{
			string table="a_dmch";
			sql="update "+table+" set ttk=:ttk";
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ttk", OracleType.NVarChar,254).Value = ttk;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,ttk) values ";
					sql+="("+id+",:ttk)";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ttk", OracleType.NVarChar,254).Value = ttk;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		#endregion camchi 270309
		#region camchi 230409
		public decimal get_Sodudauky_dt(string s_mm,string s_yy,string s_IDtk,string s_IDlk,string s_Madt,int i_Loaiton,string s_IDchuong,string s_idhoatdong,string s_idnhombc,string s_idmuc,string s_idkm,string s_idkm2,string s_idkm3,string s_idkm4)
		{
			//Neu i_Loaiton==1 lay sdno, neu i_Loaiton==1 lay sdco, neu i_Loaiton==3 lay sdno-sdco.
			decimal d_Sodudk=0;
			switch (i_Loaiton)
			{
				case 1:
				{
					sql=  "select sum(sd.sdno"+s_mm+") sddauky";
					sql+=" from a_sd"+s_yy+" sd"; 
					break;
				}
				case 2:
				{
					sql=  "select sum(sd.sdco"+s_mm+") sddauky";
					sql+=" from a_sd"+s_yy+" sd"; 
					break;
				}
				case 3:
				{
					sql=  "select sum(sd.sdno"+s_mm+" - sd.sdco"+s_mm+") sddauky";
					sql+=" from a_sd"+s_yy+" sd"; 
					break;
				}
				default:
				{
					sql=  "select 0 sddauky";
					sql+=" from a_sd"+s_yy+" sd"; 
					break;
				}
			}
			sql+=" where sd.stka in("+s_IDtk+")";
			if (s_IDlk!="") sql+=" and lk="+s_IDlk;
			if (s_Madt!="") sql+=" and madt="+s_Madt;
			if(s_idhoatdong!="")sql+=" and hoatdong="+s_idhoatdong;
			if(s_IDchuong!="") sql+=" and chuong="+s_IDchuong;
			if(s_idmuc!="")sql+=" and mtmuc="+s_idmuc;
			if(s_idkm!="")sql+=" and khoanmuc="+s_idkm;
			if(s_idkm2!="")sql+=" and khoanmuc2="+s_idkm2;
			if(s_idkm3!="")sql+=" and khoanmuc3="+s_idkm3;
			if(s_idkm4!="")sql+=" and khoanmuc4="+s_idkm4;
			try
			{
				d_Sodudk=decimal.Parse(get_data(sql).Tables[0].Rows[0][0].ToString());
			}
			catch{};
			return d_Sodudk;
		}
		public string get_Sodudauky_dt_m2(string s_mm,string s_yy,string s_IDtk,string s_IDlk,string s_Madt,int i_Loaiton,string s_IDchuong,string s_idhoatdong,string s_idnhombc,string s_idmuc,string s_idkm,string s_idkm2,string s_idkm3,string s_idkm4,int i_dkgroup)
		{
			string sql="",s_DKSelectgroup="",s_DKGroupbygroup="",s_DKfrom="",s_DKwhere="",s_DKgroup="";	

			if(i_dkgroup!=-1) s_DKgroup=", "+i_dkgroup+" as nhom";
			else s_DKgroup=", -1 as nhom ";	
			switch(i_dkgroup)
			{
				case 0:
					s_DKSelectgroup=" sd.chuong as idchuong, ch.ten as chuong,";
					s_DKGroupbygroup=" group by sd.chuong, ch.ten";
					s_DKGroupbygroup+=", madt";
					s_DKfrom=" , "+user+".a_dmchuong ch";
					s_DKwhere=" and sd.chuong=ch.id";
					break;
				case 1:
					s_DKSelectgroup=" sd.madt as iddoituong, dt.tendt as doituong,";
					s_DKGroupbygroup=" group by sd.madt,dt.tendt";
					s_DKGroupbygroup+=", madt";
					s_DKfrom=" , "+user+".a_dmdt dt";
					s_DKwhere=" and sd.madt=dt.id";
					break;
				case 2:
					s_DKSelectgroup=" sd.hoatdong as idhoatdong, hd.ten as hoatdong,";
					s_DKGroupbygroup=" group by sd.hoatdong,hd.ten";
					s_DKGroupbygroup+=", madt";
					s_DKfrom=" , "+user+".a_hoatdong hd";
					s_DKwhere=" and sd.hoatdong=hd.id";
					break;
				case 3:
					s_DKSelectgroup=" sd.mtmuc as idmuc, ch.ttk as muc,";
					s_DKGroupbygroup=" group by sd.mtmuc,ch.ttk";
					s_DKGroupbygroup+=", madt";
					s_DKfrom=" , "+user+".a_dmch ch";
					s_DKwhere=" and sd.mtmuc=ch.id";
					break;
				case 4:
					s_DKSelectgroup=" sd.idbc as idnhombc, bc.ten as nhombc, ";
					s_DKGroupbygroup=" group by sd.idbc,bc.ten";
					s_DKGroupbygroup+=", madt";
					s_DKfrom=" , "+user+".a_dmnhombc bc";
					s_DKwhere=" and sd.idbc=bc.id";
					break;
				case 5:
					s_DKSelectgroup=" sd.khoanmuc as idkm, km.ten as km,";
					s_DKGroupbygroup=" group by sd.khoanmuc,km.ten";
					s_DKGroupbygroup+=", madt";
					s_DKfrom=" , "+user+".a_dmkhoanmuc km";
					s_DKwhere=" and sd.khoanmuc=km.id";
					break;
				case 6:
					s_DKSelectgroup=" sd.khoanmuc2 as idkm2, km.ten as km2,";
					s_DKGroupbygroup=" group by sd.khoanmuc2,km.ten";
					s_DKGroupbygroup+=", madt";
					s_DKfrom=" , "+user+".a_dmkhoanmuc km";
					s_DKwhere=" and sd.khoanmuc2=km.id";
					break;
				case 7:
					s_DKSelectgroup=" sd.khoanmuc3 as idkm3, km.ten as km3,";
					s_DKGroupbygroup=" group by sd.khoanmuc3,km.ten";
					s_DKGroupbygroup+=", madt";
					s_DKfrom=" , "+user+".a_dmkhoanmuc km";
					s_DKwhere=" and sd.khoanmuc3=km.id";
					break;
				case 8:
					s_DKSelectgroup=" sd.khoanmuc4 as idkm4, km.ten as km4,";
					s_DKGroupbygroup=" group by sd.khoanmuc4,km.ten";
					s_DKGroupbygroup+=", madt";
					s_DKfrom=" , "+user+".a_dmkhoanmuc km";
					s_DKwhere=" and sd.khoanmuc4=km.id";
					break;
				default: 
					s_DKSelectgroup="";
					s_DKGroupbygroup=" group by sd.stka";
					s_DKGroupbygroup+=", madt";
					break;
			}
			sql=" select t1.*,t2.tendt from(";			
			sql+=" select sum(sd.sdno"+s_mm+") sddaukyno,madt as id,";
			sql+=" "+s_DKSelectgroup+"";
			sql+=  " sum(sd.sdco"+s_mm+") sddaukyco,";
			sql+=" 0 as sotienno, 0 as sotienco, 0 as fsluykeno,0 as fsluykeco";
			sql+=" "+s_DKgroup+"";
			sql+=" from a_sd"+s_yy+" sd"; 
			sql+=" "+s_DKfrom+"";
			sql+=" where sd.stka in("+s_IDtk+")";
			sql+=" "+s_DKwhere+"";
			if (s_IDlk!="") sql+=" and lk='"+s_IDlk+"'";
			if (s_Madt!="") sql+=" and madt='"+s_Madt+"'";
			if(s_idhoatdong!="")sql+=" and hoatdong="+s_idhoatdong;
			if(s_IDchuong!="") sql+=" and chuong="+s_IDchuong;
			if(s_idmuc!="")sql+=" and mtmuc="+s_idmuc;
			if(s_idkm!="")sql+=" and khoanmuc="+s_idkm;
			if(s_idkm2!="")sql+=" and khoanmuc2="+s_idkm2;
			if(s_idkm3!="")sql+=" and khoanmuc3="+s_idkm3;
			if(s_idkm4!="")sql+=" and khoanmuc4="+s_idkm4;
			//sql+=" group by madt";
			sql+=" "+s_DKGroupbygroup+"";
			sql+=" )t1";
			sql+=" left join (select * from a_dmdt dt )t2 on t1.id=t2.id";
			return sql;
		}
		public string get_FSluykenam_dt_m2(string s_mm,string s_yy,string s_IDtk,string s_IDlk,string s_Madt,int i_Loaitk,string s_IDchuong,string s_idhoatdong,string s_idnhombc,string s_idmuc,string s_idkm,string s_idkm2,string s_idkm3,string s_idkm4, int i_dkgroup)
		{			
			string sql="",s_DKSelectgroup="",s_DKGroupbygroup="",s_DKfrom="",s_DKwhere="",s_DKgroup="";	

			if(i_dkgroup!=-1) s_DKgroup=", "+i_dkgroup+" as nhom";
			else s_DKgroup=", -1 as nhom ";	
			switch(i_dkgroup)
			{
				case 0:
					s_DKSelectgroup=" sd.chuong as idchuong, ch.ten as chuong,";
					s_DKGroupbygroup=" group by sd.chuong, ch.ten";
					s_DKGroupbygroup+=", madt";
					s_DKfrom=" , "+user+".a_dmchuong ch";
					s_DKwhere=" and sd.chuong=ch.id";
					break;
				case 1:
					s_DKSelectgroup=" sd.madt as iddoituong, dt.tendt as doituong,";
					s_DKGroupbygroup=" group by sd.madt,dt.tendt";
					s_DKGroupbygroup+=", madt";
					s_DKfrom=" , "+user+".a_dmdt dt";
					s_DKwhere=" and sd.madt=dt.id";
					break;
				case 2:
					s_DKSelectgroup=" sd.hoatdong as idhoatdong, hd.ten as hoatdong,";
					s_DKGroupbygroup=" group by sd.hoatdong,hd.ten";
					s_DKGroupbygroup+=", madt";
					s_DKfrom=" , "+user+".a_hoatdong hd";
					s_DKwhere=" and sd.hoatdong=hd.id";
					break;
				case 3:
					s_DKSelectgroup=" sd.mtmuc as idmuc, ch.ttk as muc,";
					s_DKGroupbygroup=" group by sd.mtmuc,ch.ttk";
					s_DKGroupbygroup+=", madt";
					s_DKfrom=" , "+user+".a_dmch ch";
					s_DKwhere=" and sd.mtmuc=ch.id";
					break;
				case 4:
					s_DKSelectgroup=" sd.idbc as idnhombc, bc.ten as nhombc, ";
					s_DKGroupbygroup=" group by sd.idbc,bc.ten";
					s_DKGroupbygroup+=", madt";
					s_DKfrom=" , "+user+".a_dmnhombc bc";
					s_DKwhere=" and sd.idbc=bc.id";
					break;
				case 5:
					s_DKSelectgroup=" sd.khoanmuc as idkm, km.ten as km,";
					s_DKGroupbygroup=" group by sd.khoanmuc,km.ten";
					s_DKGroupbygroup+=", madt";
					s_DKfrom=" , "+user+".a_dmkhoanmuc km";
					s_DKwhere=" and sd.khoanmuc=km.id";
					break;
				case 6:
					s_DKSelectgroup=" sd.khoanmuc2 as idkm2, km.ten as km2,";
					s_DKGroupbygroup=" group by sd.khoanmuc2,km.ten";
					s_DKGroupbygroup+=", madt";
					s_DKfrom=" , "+user+".a_dmkhoanmuc km";
					s_DKwhere=" and sd.khoanmuc2=km.id";
					break;
				case 7:
					s_DKSelectgroup=" sd.khoanmuc3 as idkm3, km.ten as km3,";
					s_DKGroupbygroup=" group by sd.khoanmuc3,km.ten";
					s_DKGroupbygroup+=", madt";
					s_DKfrom=" , "+user+".a_dmkhoanmuc km";
					s_DKwhere=" and sd.khoanmuc3=km.id";
					break;
				case 8:
					s_DKSelectgroup=" sd.khoanmuc4 as idkm4, km.ten as km4,";
					s_DKGroupbygroup=" group by sd.khoanmuc4,km.ten";
					s_DKGroupbygroup+=", madt";
					s_DKfrom=" , "+user+".a_dmkhoanmuc km";
					s_DKwhere=" and sd.khoanmuc4=km.id";
					break;
				default: 
					s_DKSelectgroup="";
					s_DKGroupbygroup=" group by sd.stka";
					s_DKGroupbygroup+=", madt";
					break;
			}
			int i_den=int.Parse(s_mm);
			int i=1;
			for (i=1;i<i_den;i++)
			{
				string s_Thang_i=i.ToString().PadLeft(2,'0');
				sql=" select t1.*,t2.tendt from(";				
				sql+=" select sum(sd.fsno"+s_Thang_i+") fsluykeno,";
				sql+=" "+s_DKSelectgroup+"";
				sql+=  " sum(sd.fsco"+s_Thang_i+") fsluykeco,madt as id,";	
				sql+=" 0 as sotienno, 0 as sotienco, 0 as sddaukyno,0 as sddaukyco";
				sql+=" "+s_DKgroup+"";
				sql+=" from a_sd"+s_yy+" sd"; 
				sql+=" where sd.stka in("+s_IDtk+")";
				sql+=" "+s_DKwhere+"";
				if (s_IDlk!="") sql+=" and lk='"+s_IDlk+"'";
				if (s_Madt!="") sql+=" and madt='"+s_Madt+"'";
				if(s_idhoatdong!="")sql+=" and hoatdong="+s_idhoatdong;
				if(s_IDchuong!="") sql+=" and chuong="+s_IDchuong;
				if(s_idmuc!="")sql+=" and mtmuc="+s_idmuc;
				if(s_idkm!="")sql+=" and khoanmuc="+s_idkm;
				if(s_idkm2!="")sql+=" and khoanmuc2="+s_idkm2;
				if(s_idkm3!="")sql+=" and khoanmuc3="+s_idkm3;
				if(s_idkm4!="")sql+=" and khoanmuc4="+s_idkm4;
				//sql+=" group by madt";						
				sql+=" "+s_DKGroupbygroup+"";
				if(i<i_den-1)
					sql+=" union ";
				sql+=" )t1";
				sql+=" left join ("+user+".a_dmdt)t2 on t1.id=t2.id";
			}
			if(i==1&&i_den==1)
			{
				sql= "select 0 fsluykeno";
				sql+=" 0 fsluykeco, madt as id";
				sql+=" from a_sd"+s_yy+" sd"; 
			}
			return sql;
		}
		public System.Data.DataSet get_DMDoituong(string idloaidt)
		{
			if(idloaidt!="")
			{
				sql="select trim(mavt) madt,trim(tendt) tendt,id id,loaidt,diachi,dienthoai,email,fax,masothue,sotaikhoan,nganhang,tinhtp,daidien,dtnr,dtdd,socmnd from a_dmdt where sudung=1 and loaidt="+idloaidt+" order by id";
			}
			else
				sql="select trim(mavt) madt,trim(tendt) tendt,id id,loaidt,diachi,dienthoai,email,fax,masothue,sotaikhoan,nganhang,tinhtp,daidien,dtnr,dtdd,socmnd from a_dmdt where sudung=1 order by id";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}
		public System.Data.DataSet get_DMTaikhoan(string s_Sotk1,string s_Sotk2)
		{
			if (s_Sotk1!="" && s_Sotk2!="")								
				sql=" select stk,ttk,congno,tinhchat,mlns,ctmlns,loaikm,loaikm2,loaikm3,loaikm4,id from "+user+".a_dmtk where (trim(stk) like '"+s_Sotk1+"%' or trim(stk) like '"+s_Sotk2+"%') and sudung=1 order by stk";
			else 
				sql=" select stk,ttk,congno,tinhchat,mlns,ctmlns,loaikm,loaikm2,loaikm3,loaikm4,id from "+user+".a_dmtk where sudung=1 order by stk";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}
		public string get_ID_Stk(string s_Stk,string s_Tenfrom)
		{
			string s_IDtk="";
			try
			{
				if(s_Tenfrom=="TamungKP_KhoBac")
				{
					if (s_Stk!="" && s_Stk.Trim().Substring(0,4)=="4612")
						sql="select id from a_dmtk where (trim(stk) like '"+s_Stk+"%' or trim(stk) like '"+6612+"%') order by id";
					else if(s_Stk!="")
						sql="select id from a_dmtk where trim(stk) like '"+s_Stk+"%' order by id";
				}
						foreach(System.Data.DataRow dr in get_data(sql).Tables[0].Rows)
						{ 
							s_IDtk+=dr["id"].ToString()+",";
						}
						if (s_IDtk.Substring(s_IDtk.Length-1,1)==",") s_IDtk=s_IDtk.Substring(0,s_IDtk.Length-1);					
			}
			catch{}	;
			return s_IDtk;
		}
		public bool upd_ctkc_chi(int id,decimal stt,string s_yy,int ketchuyen,string sobtoan,string tenbt,int tinhchat,int tutk,int sangtk,string kmcpnguon,string nhomkmcpn,string dtthnguon,int tukmcpn,
			string kmcpnguon2, string kmcpnguon3,string kmcpnguon4,string kmcpdich,string kmcpdich2,string kmcpdich3,string kmcpdich4,
			int tudtthn,string dtthdich,int kysl,string lknguon,int tulkn,string lkdich,int userid,DateTime ngayud)
		{
			string table="a_ctkc"+s_yy+"";
			sql="update "+table+" set stt="+stt+",ketchuyen='"+ketchuyen+"',";
			sql+=" sobtoan='"+sobtoan+"',tenbt=:tenbt,tinhchat="+tinhchat+",";
			sql+=" tutk="+tutk+",sangtk="+sangtk+",kmcpnguon="+kmcpnguon+",";
			sql+=" kmcpnguon2="+kmcpnguon2+",kmcpnguon3="+kmcpnguon3+",kmcpnguon4="+kmcpnguon4+",";
			sql+=" kmcpdich="+kmcpdich+", kmcpdich2="+kmcpdich2+",kmcpdich3="+kmcpdich3+",kmcpdich4="+kmcpdich4+",";
			sql+=" nhomkmcpn='"+nhomkmcpn+"',dtthnguon="+dtthnguon+",";
			sql+=" tukmcpn="+tukmcpn+",dtthdich="+dtthdich+",kysl="+kysl+",";
			sql+=" lknguon="+lknguon+",tulkn="+tulkn+",lkdich="+lkdich+",userid="+userid+"";
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("tenbt", OracleType.NVarChar,254).Value = tenbt;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,stt,ketchuyen,sobtoan,tenbt,tinhchat,tutk,sangtk,kmcpnguon,";
					sql+=" kmcpnguon2, kmcpnguon3,kmcpnguon4,";
					sql+=" nhomkmcpn,dtthnguon,tukmcpn,kmcpdich,kmcpdich2,kmcpdich3,kmcpdich4,";
					sql+=" tudtthn,dtthdich,kysl,lknguon,tulkn,lkdich,userid) values ";
					sql+="("+id+","+stt+","+ketchuyen+",'"+sobtoan+"',:tenbt,"+tinhchat+",";
					sql+=" "+tutk+","+sangtk+","+kmcpnguon+",'"+nhomkmcpn+"',"+dtthnguon+",";
					sql+=" "+tukmcpn+","+kmcpnguon2+","+kmcpnguon3+","+kmcpnguon4+","+kmcpdich+",";
					sql+=" "+kmcpdich2+","+kmcpdich3+","+kmcpdich4+","+tudtthn+","+dtthdich+","+kysl+",";
					sql+=" "+lknguon+","+tulkn+","+lkdich+","+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("tenbt", OracleType.NVarChar,254).Value = tenbt;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}
		public bool upd_ctkc(int id,decimal stt,string s_yy,int ketchuyen,string sobtoan,string tenbt,int tinhchat,int tutk,int sangtk,string kmcpnguon,string nhomkmcpn,string dtthnguon,int tukmcpn,
			string kmcpnguon2, string kmcpnguon3,string kmcpnguon4,string kmcpdich,string kmcpdich2,string kmcpdich3,string kmcpdich4,
			int tudtthn,string dtthdich,int kysl,string lknguon,int tulkn,string lkdich,int userid,DateTime ngayud)
		{
			string table="a_ctkc"+s_yy+"";
			sql="update "+table+" set stt="+stt+",ketchuyen='"+ketchuyen+"',";
			sql+=" sobtoan='"+sobtoan+"',tenbt=:tenbt,tinhchat="+tinhchat+",";
			sql+=" tutk="+tutk+",sangtk="+sangtk+",kmcpnguon='"+kmcpnguon+"',";
			sql+=" kmcpnguon2='"+kmcpnguon2+"',kmcpnguon3='"+kmcpnguon3+"',kmcpnguon4='"+kmcpnguon4+"',";
			sql+=" kmcpdich='"+kmcpdich+"', kmcpdich2='"+kmcpdich2+"',kmcpdich3='"+kmcpdich3+"',kmcpdich4='"+kmcpdich4+"',";
			sql+=" nhomkmcpn='"+nhomkmcpn+"',dtthnguon='"+dtthnguon+"',";
			sql+=" tukmcpn="+tukmcpn+",dtthdich='"+dtthdich+"',kysl="+kysl+",";
			sql+=" lknguon='"+lknguon+"',tulkn="+tulkn+",lkdich='"+lkdich+"',userid="+userid+"";
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("tenbt", OracleType.NVarChar,254).Value = tenbt;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,stt,ketchuyen,sobtoan,tenbt,tinhchat,tutk,sangtk,kmcpnguon,";
					sql+=" kmcpnguon2, kmcpnguon3,kmcpnguon4,";
					sql+=" nhomkmcpn,dtthnguon,tukmcpn,kmcpdich,kmcpdich2,kmcpdich3,kmcpdich4,";
					sql+=" tudtthn,dtthdich,kysl,lknguon,tulkn,lkdich,userid) values ";
					sql+="("+id+","+stt+","+ketchuyen+",'"+sobtoan+"',:tenbt,"+tinhchat+",";
					sql+=" "+tutk+","+sangtk+",'"+kmcpnguon+"','"+kmcpnguon2+"','"+kmcpnguon3+"','"+kmcpnguon4+"','"+nhomkmcpn+"','"+dtthnguon+"',";
					sql+=" "+tukmcpn+",'"+kmcpdich+"',";
					sql+=" '"+kmcpdich2+"','"+kmcpdich3+"','"+kmcpdich4+"',"+tudtthn+",'"+dtthdich+"',"+kysl+",";
					sql+=" '"+lknguon+"',"+tulkn+",'"+lkdich+"',"+userid+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("tenbt", OracleType.NVarChar,254).Value = tenbt;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}
		public DataSet get_DMNhom()
		{
			sql="SELECT n,ttk,id FROM "+user+".a_dmch ORDER BY id";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}
		public DataSet get_DMTN(string s_nhom)
		{
			sql="SELECT tn,ttk,id FROM "+user+".a_dmch where n='"+s_nhom+"' ORDER BY id";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}
		public System.Data.DataSet get_DMTMCT(string s_nhom,string s_tnhom,string s_muc,string s_tm)
		{
			sql="select substr(trim(mtm),11,2) as tmct,trim(ttk) ttk,id from "+user+".a_dmch where sudung=1 and cd=1 and n='"+s_nhom+"' and tn='"+s_tnhom+"' and substr(trim(mtm),1,4)='"+s_muc+"' and substr(trim(mtm),6,4)='"+s_tm+"' order by trim(mtm),ttk";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}
		public System.Data.DataSet get_DMTMuc(string s_nhom,string s_tnhom,string s_muc)
		{
			sql="select substr(trim(mtm),6,4) as tm,trim(ttk) ttk,id from "+user+".a_dmch where sudung=1 and cd=2 and n='"+s_nhom+"' and tn='"+s_tnhom+"' and substr(trim(mtm),1,4)='"+s_muc+"' order by trim(mtm),ttk";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}
		public System.Data.DataSet get_DMMuc(string s_nhom,string s_tnhom)
		{
			sql="select trim(mtm) muc,trim(ttk) ttk,id from "+user+".a_dmch where sudung=1 and cd=3 and n='"+s_nhom+"' and tn='"+s_tnhom+"' order by trim(mtm),ttk";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}
		public bool upd_dmmlns(long id,string p,string n,string tn,string stk, string cc, string ttk,int cd,int sp,int nhmuc,int sudung,int huy,int userid,string mtm,DateTime t_ngayud)
		{
			string table=""+user+".a_dmch";
			sql="update "+table+" set p='"+p+"',n='"+n+"',tn='"+tn+"', stk='"+stk+"', cc='"+cc+"',ttk=:ttk,";
			sql+=" cd="+cd+",sp="+sp+",nhmuc="+nhmuc+",sudung="+sudung+",huy="+huy+",userid="+userid+",mtm='"+mtm+"'";
			sql+=" where id="+id;
			con=new OracleConnection(sConn);
			try
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("ttk", OracleType.NVarChar,254).Value = ttk;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="insert into "+table+"(id,p,n,tn,stk,cc,ttk,cd,sp,nhmuc,sudung,huy,userid,mtm)";
					sql+=" values ("+id+",'"+p+"','"+n+"','"+tn+"','"+stk+"','"+cc+"',:ttk,"+cd+","+sp+","+nhmuc+","+sudung+","+huy+","+userid+",";
					sql+=" '"+mtm+"')";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("ttk", OracleType.NVarChar,254).Value = ttk;
					cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			}
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}
		#endregion camchi 230409
		#region ThanhHuong 07082009
		public DataSet get_dmtkCTcungloai(string s_stk1,string s_stk2)
		{
			if (s_stk1!="" && s_stk2!="")								
				sql=" select stk,ttk,congno,tinhchat,mlns,ctmlns,loaikm,loaikm2,loaikm3,loaikm4,id from "+user+".a_dmtk where (trim(stk) like '"+s_stk1+"%' or trim(stk) like '"+s_stk2+"%') and sudung=1 order by stk";
			else 
				sql=" select stk,ttk,congno,tinhchat,mlns,ctmlns,loaikm,loaikm2,loaikm3,loaikm4,id from "+user+".a_dmtk where sudung=1 order by stk";
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}
		public string get_stk_id(int s_idstk)
		{
			DataSet ds_tk=new DataSet();
			string s_tk="";
			try
			{
				if (s_idstk!=0)
				{
					sql="select stk from "+user+".a_dmtk where id="+s_idstk+" order by id";					
				}
				ds_tk=get_data(sql).Copy();
				s_tk=ds_tk.Tables[0].Rows[0][0].ToString();
			}
			catch{}	;
			return s_tk;

		}
		public string ttk_id(int s_idstk)
		{
			DataSet ds_tk=new DataSet();
			string s_tk="";
			try
			{
				if (s_idstk!=0)
				{
					sql="select ttk from "+user+".a_dmtk where id="+s_idstk+" order by id";					
				}
				ds_tk=get_data(sql).Copy();
				s_tk=ds_tk.Tables[0].Rows[0][0].ToString();
			}
			catch{}	;
			return s_tk;
		}

		public string get_id_stk(string s_idstk)
		{
			DataSet ds_tk=new DataSet();
			string s_tk="";
			try
			{
				if (s_idstk!="")
				{
					sql="select id from "+user+".a_dmtk where stk="+s_idstk+" order by id";					
				}
				ds_tk=get_data(sql).Copy();
				s_tk=ds_tk.Tables[0].Rows[0][0].ToString();
			}
			catch{}	;
			return s_tk;

		}
		public string khoanmuc_id(string stk,string makm)
		{
			string idkm="";
			sql="select km.id from "+user+".a_dmkhoanmuc km inner join "+user+".a_dmloaikm lk on lk.id=km.loaikm ";
			sql+=" inner join  "+user+".a_dmtk tk on lk.id=tk.loaikm where km.sudung=1 and km.ma in ("+makm+")";
			if(stk!="")sql+=" and tk.stk like '"+stk+"%' ";
			ds=get_data(sql).Copy();
			if(ds.Tables[0].Rows.Count==0)
				return null;
			else if(ds.Tables[0].Rows.Count==1)
				idkm=ds.Tables[0].Rows[0][0].ToString();
			else 
			{
				foreach(System.Data.DataRow dr in ds.Tables[0].Rows)
				{ 
					idkm+=dr["id"].ToString()+",";
				}
				if (idkm.Substring(idkm.Length-1,1)==",") idkm=idkm.Substring(0,idkm.Length-1);	
			}
			return idkm;
		}

		public DataSet get_sdr(string nt_lkfsndk, string nt_lkfscdk, string nt_lkfsnkn, string nt_lkfsckn, string lkfsndk, string lkfscdk, string lkfsnkn,
			string lkfsckn, string table1, string table2, string fsno, string fsco)
		{
			con=new OracleConnection(sConn);
			con.Open();
			cmd=new OracleCommand("pkg_ketoan.get_sdr",con);
			cmd.CommandType=CommandType.StoredProcedure;
			
			cmd.Parameters.Add("io_cursor",OracleType.Cursor).Direction=ParameterDirection.Output;

			dest=new OracleDataAdapter(cmd);
			DataSet ds=new DataSet();
			dest.Fill(ds);
			cmd.Dispose();
			con.Close();
			con.Dispose();
			return ds;
		}
		public DataSet get_pkgkt_sdr(string table1, string table2 )			
		{
			con=new OracleConnection(sConn);
			con.Open();
			cmd=new OracleCommand("pkg_ketoan.get_sdr",con);
			cmd.CommandType=CommandType.StoredProcedure;

			
//			cmd.Parameters.Add("table1",OracleType.VarChar,256).Value=table1.Trim();
			cmd.Parameters.Add("table2",OracleType.VarChar,10).Value=table2.Trim();
					
			cmd.Parameters.Add("io_cursor",OracleType.Cursor ).Direction=ParameterDirection.Output;
			dest=new OracleDataAdapter(cmd);
			DataSet ds=new DataSet();
			dest.Fill(ds);
			cmd.Dispose();
			con.Dispose();
			return ds;
		}
		public DataSet get_pkgkt_dmm()			
		{
			con=new OracleConnection(sConn);
			con.Open();
			cmd=new OracleCommand("pkg_kt.get_tk",con);
			cmd.CommandType=CommandType.StoredProcedure;
			cmd.Parameters.Add("feild",OracleType.VarChar,256).Value="MAUBIEU";
			cmd.Parameters.Add("tablename",OracleType.VarChar,256).Value="a_dmmaubc";			
			cmd.Parameters.Add("io_cursor",OracleType.Cursor ).Direction=ParameterDirection.Output;
			dest=new OracleDataAdapter(cmd);
			DataSet ds=new DataSet();
			dest.Fill(ds,"tabe");
			cmd.Dispose();
			con.Dispose();
			return ds;
		}
		public DataSet get_maubc()
		{
			sql="select id,tt,maubieu,ten from "+user+".a_dmmaubc where tt=1 or tt=13 or tt=14 order by tt";		
			try
			{
				ds=get_data(sql).Copy();
				if (ds!=null && ds.Tables[0].Rows.Count>0)
					return ds;
				else return null;
			}
			catch
			{
				return null;
			}
		}

		public bool execute_data(ArrayList arr)
		{
			try
			{
				con=new OracleConnection(sConn);
				con.Open();
				foreach (string i in arr)
				{
					cmd=new OracleCommand(i.ToString(),con);
					cmd.CommandType=CommandType.Text;
					cmd.ExecuteNonQuery();
				}
				cmd.Dispose();
				con.Close();con.Dispose();
				return true;
			}
			catch(OracleException ex)
			{
				upd_error(ex.Message.ToString().Trim(),sComputer,"?");
				return false;
			}
		}
		public decimal get_Sodudauky_scttk(string s_mm,string s_yy,string s_IDtk,string s_IDlk,string s_Madt,int i_Loaiton)
		{
			//Neu i_Loaiton==1 lay sdno, neu i_Loaiton==1 lay sdco, neu i_Loaiton==3 lay sdno-sdco.
			decimal d_Sodudk=0;
			switch (i_Loaiton)
			{
				case 1:
				{
					sql=  "select sum(sd.sdno"+s_mm+") sddauky";
					sql+=" from "+user+".a_sd"+s_yy+" sd"; 
					break;
				}
				case 2:
				{
					sql=  "select sum(sd.sdco"+s_mm+") sddauky";
					sql+=" from "+user+".a_sd"+s_yy+" sd"; 
					break;
				}
				case 3:
				{
					sql=  "select sum(sd.sdno"+s_mm+" - sd.sdco"+s_mm+") sddauky";
					sql+=" from "+user+".a_sd"+s_yy+" sd"; 
					break;
				}
				default:
				{
					sql=  "select 0 sddauky";
					sql+=" from "+user+".a_sd"+s_yy+" sd"; 
					break;
				}
			}
			sql+=" where sd.stka ="+s_IDtk+"";
			if (s_IDlk!="") sql+=" and lk='"+s_IDlk+"'";
			if (s_Madt!="") sql+=" and madt='"+s_Madt+"'";
			try
			{
				d_Sodudk=decimal.Parse(get_data(sql).Tables[0].Rows[0][0].ToString());
			}
			catch{};
			return d_Sodudk;
		}

		public decimal get_FSluykenam_quy_scttk(string s_yy,string s_sotk,string s_IDlk,int i_Loaitk, int CT_Quy,int i_tu,string s_IDChuong, string s_IDHoatdong,string s_IDNhombc,string s_IDdoituong,string s_IDmuc,string s_IDkm,string s_IDkm2,string s_IDkm3,string s_IDkm4)// bool b_checkChuong, string idChuong, bool b_checkHoatDong, string idHoatDong, string idNhombc, bool b_checkNhombc)
		{
			decimal d_FSluyke=0;
			for (int i=CT_Quy;i<i_tu;i++)
			{
				string s_Thang_i=i.ToString().PadLeft(2,'0');
				if (i_Loaitk==1) sql=  "select sum(sd.fsno"+s_Thang_i+") fsluyke";
				else sql=  "select sum(sd.fsco"+s_Thang_i+") fsluyke";
				sql+=" from a_sd"+s_yy+" sd,a_dmtk b";
				sql+=" where sd.stka=b.id and b.id = "+s_sotk+"";
				if (s_IDlk!="") sql+=" and lk='"+s_IDlk+"'";
				if(s_IDChuong!="")sql+=" and sd.chuong="+s_IDChuong;
				if(s_IDHoatdong!="")sql+=" and sd.hoatdong="+s_IDHoatdong;
				if(s_IDNhombc!="")sql+=" and sd.idbc="+s_IDNhombc;
				if(s_IDdoituong!="")sql+=" and madt='"+s_IDdoituong+"'";
				if(s_IDmuc!="")sql+=" and sd.mtmuc='"+s_IDmuc+"'";
				if (s_IDkm!="") sql+=" and sd.khoanmuc = '"+s_IDkm+"'";		
				if (s_IDkm2!="") sql+=" and sd.khoanmuc2 = '"+s_IDkm2+"'";			
				if (s_IDkm3!="") sql+=" and sd.khoanmuc3 = '"+s_IDkm3+"'";			
				if (s_IDkm4!="") sql+=" and sd.khoanmuc4 = '"+s_IDkm4+"'";

				try
				{
					d_FSluyke+=decimal.Parse(get_data(sql).Tables[0].Rows[0][0].ToString());
				}
				catch{};
			}
			return d_FSluyke;
		}
		
		public bool updCtnghang(string mmyy,long id,int idbc,string mact,int chuong,int chucnang,int hoatdong,int lctug,string soctg,
			string ngayg,string ngaygs,string noidung,long tknoa,long tkcoa,int loaidt,long madt,
			decimal stien,decimal nguyente,string thanggs,int nghiepvu,int loaibk,int tcnkp,long hopdong,
			string ctgs,long iddongthoi,int userid,int manns)
		{
			string table=user+".a_ct"+mmyy.Substring(2);
			sql="update "+table+" set idbc="+idbc+",mact='"+mact+"',chuong="+chuong+",chucnang="+chucnang+",hoatdong="+hoatdong+",lctug="+lctug;
			sql+=",soctg='"+soctg+"',ngayg=to_date('"+ngayg+"','dd/mm/yyyy')";
			sql+=",ngaygs=to_date('"+ngaygs+"','dd/mm/yyyy'),noidung=:noidung,tknoa="+tknoa+",tkcoa="+tkcoa;
			sql+=",loaidt="+loaidt+",madt="+madt+",stien="+stien;
			sql+=",nguyente="+nguyente+",thanggs='"+thanggs+"',nghiepvu="+nghiepvu+",loaibk="+loaibk;
			sql+=",tcnkp="+tcnkp+",hopdong="+hopdong+",ctgs='"+ctgs+"'";
			sql+=",iddongthoi="+iddongthoi+",userid="+userid+",manns="+manns+" where id="+id;
			con=new OracleConnection(sConn);
			try 
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("noidung", OracleType.NVarChar,254).Value = noidung;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="INSERT INTO "+table+" (id,idbc,mact,chuong,chucnang,hoatdong,lctug,soctg,ngayg,ngaygs,noidung,tknoa,tkcoa,";
					sql+="loaidt,madt,stien,nguyente,thanggs,nghiepvu,loaibk,tcnkp,hopdong,ctgs,iddongthoi,userid,manns)";
					sql+=" VALUES("+id+","+idbc+",'"+mact+"',"+chuong+","+chucnang+","+hoatdong+","+lctug+",'"+soctg+"',to_date('"+ngayg+"','dd/mm/yyyy')";
					sql+=",to_date('"+ngaygs+"','dd/mm/yyyy'),:noidung,"+tknoa+","+tkcoa;
					sql+=","+loaidt+","+madt+","+stien+","+nguyente+",'"+thanggs+"',"+nghiepvu+","+loaibk+","+tcnkp;
					sql+=","+hopdong+",'"+ctgs+"',"+iddongthoi+","+userid+","+manns+")";
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("noidung", OracleType.NVarChar,254).Value = noidung;
					irec=cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			} 
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}

		public bool upddmngns(long id,string mans,string tenns,string mada, string tenda,int sudung,int userid)
		{
			string table=user+".a_dmngns";
			sql="update "+table+" set mans=:mans,tenns=:tenns,mada=:mada,tenda=:tenda,sudung="+sudung+",userid="+userid+" where id="+id;
			con=new OracleConnection(sConn);
			try 
			{
				con.Open();
				cmd=new OracleCommand(sql,con);
				cmd.CommandType=CommandType.Text;
				cmd.Parameters.Add("mans", OracleType.NVarChar,254).Value = mans;
				cmd.Parameters.Add("tenns", OracleType.NVarChar,254).Value = tenns;
				cmd.Parameters.Add("mada", OracleType.NVarChar,254).Value = mada;
				cmd.Parameters.Add("tenda", OracleType.NVarChar,254).Value = tenda;
				int irec=cmd.ExecuteNonQuery();
				cmd.Dispose();
				if (irec==0)
				{
					sql="INSERT INTO "+table+" (id,mans,tenns,mada,tenda,sudung,userid)";
					sql+=" VALUES("+id+",:mans,:tenns,:mada,:tenda,"+sudung+","+userid+")";					
					cmd=new OracleCommand(sql,con);
					cmd.CommandType=CommandType.Text;
					cmd.Parameters.Add("mans", OracleType.NVarChar,254).Value = mans;
					cmd.Parameters.Add("tenns", OracleType.NVarChar,254).Value = tenns;
					cmd.Parameters.Add("mada", OracleType.NVarChar,254).Value = mada;
					cmd.Parameters.Add("tenda", OracleType.NVarChar,254).Value = tenda;
					irec=cmd.ExecuteNonQuery();
					cmd.Dispose();
				}
			} 
			catch(Exception ex)
			{
				upd_error(ex.Message,sComputer,table);
				return false;
			}
			finally
			{
				con.Close();con.Dispose();
			}
			return true;
		}
		#endregion
		#region trang040909
		public DataSet _rpthethongtaikhoan(string _Id)
		{
			string sql="";
			DataSet _DataSet =new DataSet();
			doiso.Doisototext doiso =new doiso.Doisototext();
			if(_Id.Trim().Equals("Tìm kiếm"))
			{
				sql="select a.*,b.ten as tentinhchat,nvl(a.tonghop,' ') as thop from a_dmtk a,a_dmtctk b where a.tinhchat=b.id order by a.stk";
				_DataSet=get_data(sql);
			}
			else
			{
				sql="select a.*,b.ten as tentinhchat,nvl(a.tonghop,' ') as thop from a_dmtk a,a_dmtctk b where a.tinhchat=b.id and a.stk like '%"+_Id+"'order by a.stk";
				_DataSet=get_data(sql);
			}	
			
			//_DataSet.WriteXml("D:\\rpthethongtaikhoan.xml",XmlWriteMode.WriteSchema);
			return _DataSet;
		}
		public DataSet _rdanhmucnganhang()
		{
			DataSet _DataSet =new DataSet();
			doiso.Doisototext doiso=new doiso.Doisototext();
			string sql="select a.*,b.stk as sotk,b.ttk from a_dmnh a,a_dmtk b where a.stk=b.id order by a.stt";
			_DataSet=get_data(sql);
			//_DataSet.WriteXml("D:\\rdanhmuctaikhoannganhang.xml",XmlWriteMode.WriteSchema);
			return _DataSet;
		}
		public DataSet _rdanhmucloaikhoan()
		{
			DataSet _DataSet =new DataSet();
			doiso.Doisototext doiso=new doiso.Doisototext();
			string sql="select * from a_dmlk order by stt";
			_DataSet =get_data(sql);
			//_DataSet.WriteXml("D:\\rdanhmucloaikhoan.xml",XmlWriteMode.WriteSchema);
			return _DataSet;
		}
		public DataSet _rdanhmucbophan()
		{
			DataSet _DataSet =new DataSet();
			doiso.Doisototext doiso=new doiso.Doisototext();
			string sql="select * from a_btdkp order by stt";
			_DataSet=get_data(sql);
			//_DataSet.WriteXml("D:\\rdanhmucbophan.xml",XmlWriteMode.WriteSchema);
			return _DataSet;
		}
		public DataSet _rdanhmucnguonkinhphi(long _id)
		{
			DataSet _DataSet =new DataSet();
			doiso.Doisototext doiso=new doiso.Doisototext();			
			string sql="select * from a_dmng where loaikp="+_id+"order by stt";
			_DataSet=get_data(sql);
			//_DataSet.WriteXml("D:\\rdanhmucnguonkinhphi.xml",XmlWriteMode.WriteSchema);
			return _DataSet;
		}
		public DataSet _rdanhmucduan(string text)
		{
			DataSet _DataSet =new DataSet();
			doiso.Doisototext doiso=new doiso.Doisototext();
			string sql="select a.*,to_char(a.ngaybd,'dd/mm/yyyy') as bd,to_char(a.ngaykt,'dd/mm/yyyy') as kt  from a_dmng a where mada like '%"+text.Trim()+"%' or ten like '%"+text.Trim()+"%' or thuocct like '%"+text.Trim()+"%' or coquanth like '%"+text.Trim()+"%'";
			_DataSet=get_data(sql);
			//_DataSet.WriteXml("D:\\rdanhmucduan.xml",XmlWriteMode.WriteSchema);
			return _DataSet;
		}
		public DataSet  _rdanhmuctieumuc(string txt,string user)
		{
			string sql="";
			DataSet _DataSet =new DataSet();
			doiso.Doisototext doiso =new doiso.Doisototext();
			if(!txt.Trim().Equals("Tìm kiếm"))
			{
				sql="select ch.id as id,p,n,tn,stk,mtm,cc,ttk,cd,sp,ch.nhmuc as nhmuc,nh.nhom as nhom,nh.tennhom as tennhom,ch.sudung as sudung,ch.userid as userid,ch.ngayud as ngayud from  "+user+".a_dmch ch left join "+user+".a_dmnhom nh on ch.nhmuc=nh.id where mtm like '%"+txt+"%' or stk like '%"+txt+"%'order by cc";
				_DataSet=get_data(sql);
			}
			else
			{
				sql="select ch.id as id,p,n,tn,stk,mtm,cc,ttk,cd,sp,ch.nhmuc as nhmuc,nh.nhom as nhom,nh.tennhom as tennhom,ch.sudung as sudung,ch.userid as userid,ch.ngayud as ngayud from "+user+".a_dmch ch left join "+user+".a_dmnhom nh on ch.nhmuc=nh.id order by cc";
				_DataSet=get_data(sql);
			}	
			
			//_DataSet.WriteXml("D:\\_rdanhmuctieumuc.xml",XmlWriteMode.WriteSchema);
			return _DataSet;
		
		}
		public DataSet _rdanhmucnhanvien(string txt)
		{
			string sql="";
			DataSet _DataSet =new DataSet();
			doiso.Doisototext doiso =new doiso.Doisototext();
			if(txt.Trim().Equals("Tìm kiếm"))
			{
				sql="select a.*,to_char(a.capngay,'dd/mm/yyyy') as ngay,b.hoten  from a_dmdt a,dmbs b  where a.medisoft=b.ma(+) and a.loaidt=0 order by a.stt";
				_DataSet=get_data(sql);
			}
			else
			{				
				sql="select a.*,to_char(a.capngay,'dd/mm/yyyy') as ngay,b.hoten  from a_dmdt a,dmbs b  where a.medisoft=b.ma(+) and a.loaidt=0  and  (madt like '%"+txt+"%' or upper(tendt) like '%"+txt.ToUpper()+"%' or masothue like '%"+txt+"%' or sotaikhoan like '%"+txt+" %') order by a.stt";
				_DataSet=get_data(sql);
			}	
			
			//_DataSet.WriteXml("D:\\_rdanhmucnhanvien.xml",XmlWriteMode.WriteSchema);
			return _DataSet;
		
		}
		public DataSet _rdanhmuckhachhang(string text)
		{
			string sql="";
			DataSet _DataSet =new DataSet();
			doiso.Doisototext doiso =new doiso.Doisototext();
			if(text .Trim().Equals("Tìm kiếm"))
			{
				sql="select a.*,to_char(a.capngay,'dd/mm/yyyy') as ngay,b.ten as tenloai,c.ten as tennx  from a_dmdt a,a_dmloaidt b,d_dmnx c  where a.loaidt=b.id and a.manx=c.id(+) and a.loaidt>0 order by a.stt ";
				_DataSet=get_data(sql);
			}
			else
			{				
				sql="select a.*,to_char(a.capngay,'dd/mm/yyyy') as ngay,b.ten as tenloai,c.ten as tennx  from a_dmdt a,a_dmloaidt b,d_dmnx c  where a.loaidt=b.id and a.manx=c.id(+) and a.loaidt>0 and (a.mavt like '%"+text.Trim()+"%' or upper(a.tendt) like '%"+text.ToUpper() +"%' or a.masothue like '%"+text.Trim()+"%' or a.sotaikhoan like '%"+text.Trim()+" %')order by a.stt ";
				_DataSet=get_data(sql);
			}	
			
			//_DataSet.WriteXml("D:\\_rdanhmuckhachhang.xml",XmlWriteMode.WriteSchema);
			return _DataSet;
		}
		public DataSet _rdanhmucchungtu(long _id)
		{
			DataSet _DataSet =new DataSet();
			doiso.Doisototext doiso=new doiso.Doisototext();
			string sql="select a.*,b.account,b.tennh,c.ten as tenloai from a_bcnghang a,a_dmnh b,a_dmloaiphieu c  where a.idnh=b.id(+) and a.loai=c.id  and a.chucnang="+_id+"order by a.stt";
			_DataSet=get_data(sql);
			//	_DataSet.WriteXml("D:\\rdanhmucchungtu.xml",XmlWriteMode.WriteSchema);
			
			return _DataSet;
		}
		public DataSet _rdanhmucloaikhoanmuc()
		{
			DataSet _DataSet =new DataSet();
			doiso.Doisototext doiso=new doiso.Doisototext();
			string sql="select * from a_dmloaikm order by stt";
			_DataSet=get_data(sql);
			//_DataSet.WriteXml("D:\\rloaikhoanmuc.xml",XmlWriteMode.WriteSchema);
			return _DataSet;
		}
		public DataSet _rdanhmuckhoanmuc(long _Id)
		{
			DataSet _DataSet =new DataSet();
			doiso.Doisototext doiso=new doiso.Doisototext();
			string sql="select * from a_dmkhoanmuc  where loaikm="+ _Id+"order by stt";
			_DataSet=get_data(sql);
			_DataSet.WriteXml("D:\\rdanhmuckhoanmuc.xml",XmlWriteMode.WriteSchema);
			return _DataSet;
		}
		
		#endregion
	}
}
